src/java.base/share/classes/java/math/RoundingMode.java
author xuelei
Mon, 25 Jun 2018 09:48:06 -0700
branchJDK-8145252-TLS13-branch
changeset 56807 b9e374d0534f
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Portions Copyright IBM Corporation, 2001. All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package java.math;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Specifies a <i>rounding behavior</i> for numerical operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * capable of discarding precision. Each rounding mode indicates how
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the least significant returned digit of a rounded result is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * calculated.  If fewer digits are returned than the digits needed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * represent the exact numerical result, the discarded digits will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * referred to as the <i>discarded fraction</i> regardless the digits'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * contribution to the value of the number.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * considered as a numerical value, the discarded fraction could have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * an absolute value greater than one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>Each rounding mode description includes a table listing how
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * different two-digit decimal values would round to a one digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * decimal value under the rounding mode in question.  The result
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * column in the tables could be gotten by creating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@code BigDecimal} number with the specified value, forming a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * {@link MathContext} object with the proper settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * ({@code precision} set to {@code 1}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * {@code roundingMode} set to the rounding mode in question), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * calling {@link BigDecimal#round round} on this number with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * proper {@code MathContext}.  A summary table showing the results
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * of these rounding operations for all rounding modes appears below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    54
 *<table class="striped">
8162
d91ca3f845b0 7015827: Fix HTML validation issues in java.math package
darcy
parents: 5506
diff changeset
    55
 * <caption><b>Summary of Rounding Operations Under Different Rounding Modes</b></caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    56
 * <thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    57
 * <tr><th scope="col" rowspan="2">Input Number</th><th scope="col"colspan=8>Result of rounding input to one digit with the given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *                           rounding mode</th>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 37784
diff changeset
    59
 * <tr style="vertical-align:top">
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    60
 *                               <th>{@code UP}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *                                           <th>{@code DOWN}</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *                                                        <th>{@code CEILING}</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *                                                                       <th>{@code FLOOR}</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *                                                                                    <th>{@code HALF_UP}</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *                                                                                                   <th>{@code HALF_DOWN}</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *                                                                                                                    <th>{@code HALF_EVEN}</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *                                                                                                                                     <th>{@code UNNECESSARY}</th>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    68
 * </thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    69
 * <tbody style="text-align:right">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    71
 * <tr><th scope="row">5.5</th>  <td>6</td>  <td>5</td>    <td>6</td>    <td>5</td>  <td>6</td>      <td>5</td>       <td>6</td>       <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    72
 * <tr><th scope="row">2.5</th>  <td>3</td>  <td>2</td>    <td>3</td>    <td>2</td>  <td>3</td>      <td>2</td>       <td>2</td>       <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    73
 * <tr><th scope="row">1.6</th>  <td>2</td>  <td>1</td>    <td>2</td>    <td>1</td>  <td>2</td>      <td>2</td>       <td>2</td>       <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    74
 * <tr><th scope="row">1.1</th>  <td>2</td>  <td>1</td>    <td>2</td>    <td>1</td>  <td>1</td>      <td>1</td>       <td>1</td>       <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    75
 * <tr><th scope="row">1.0</th>  <td>1</td>  <td>1</td>    <td>1</td>    <td>1</td>  <td>1</td>      <td>1</td>       <td>1</td>       <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    76
 * <tr><th scope="row">-1.0</th> <td>-1</td> <td>-1</td>   <td>-1</td>   <td>-1</td> <td>-1</td>     <td>-1</td>      <td>-1</td>      <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    77
 * <tr><th scope="row">-1.1</th> <td>-2</td> <td>-1</td>   <td>-1</td>   <td>-2</td> <td>-1</td>     <td>-1</td>      <td>-1</td>      <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    78
 * <tr><th scope="row">-1.6</th> <td>-2</td> <td>-1</td>   <td>-1</td>   <td>-2</td> <td>-2</td>     <td>-2</td>      <td>-2</td>      <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    79
 * <tr><th scope="row">-2.5</th> <td>-3</td> <td>-2</td>   <td>-2</td>   <td>-3</td> <td>-3</td>     <td>-2</td>      <td>-2</td>      <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
    80
 * <tr><th scope="row">-5.5</th> <td>-6</td> <td>-5</td>   <td>-5</td>   <td>-6</td> <td>-6</td>     <td>-5</td>      <td>-6</td>      <td>throw {@code ArithmeticException}</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    81
 * </tbody>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    82
 * </table>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>This {@code enum} is intended to replace the integer-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * enumeration of rounding mode constants in {@link BigDecimal}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * ({@link BigDecimal#ROUND_UP}, {@link BigDecimal#ROUND_DOWN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * etc. ).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see     BigDecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @see     MathContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @author  Mike Cowlishaw
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @author  Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
37784
d1c957a6806f 4943627: Deprecate rounding mode integer constants in BigDecimal and their uses
darcy
parents: 25859
diff changeset
    97
@SuppressWarnings("deprecation") // Legacy rounding mode constants in BigDecimal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
public enum RoundingMode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * Rounding mode to round away from zero.  Always increments the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         * digit prior to a non-zero discarded fraction.  Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * rounding mode never decreases the magnitude of the calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   107
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   108
         * <caption>Rounding mode UP Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   109
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   110
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   111
         *    <th scope="col">Input rounded to one digit<br> with {@code UP} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   112
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   113
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   114
         *<tr><th scope="row">5.5</th>  <td>6</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   115
         *<tr><th scope="row">2.5</th>  <td>3</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   116
         *<tr><th scope="row">1.6</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   117
         *<tr><th scope="row">1.1</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   118
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   119
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   120
         *<tr><th scope="row">-1.1</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   121
         *<tr><th scope="row">-1.6</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   122
         *<tr><th scope="row">-2.5</th> <td>-3</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   123
         *<tr><th scope="row">-5.5</th> <td>-6</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   124
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    UP(BigDecimal.ROUND_UP),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         * Rounding mode to round towards zero.  Never increments the digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         * prior to a discarded fraction (i.e., truncates).  Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * rounding mode never increases the magnitude of the calculated value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   135
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   136
         * <caption>Rounding mode DOWN Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   137
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   138
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   139
         *    <th scope="col">Input rounded to one digit<br> with {@code DOWN} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   140
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   141
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   142
         *<tr><th scope="row">5.5</th>  <td>5</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   143
         *<tr><th scope="row">2.5</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   144
         *<tr><th scope="row">1.6</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   145
         *<tr><th scope="row">1.1</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   146
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   147
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   148
         *<tr><th scope="row">-1.1</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   149
         *<tr><th scope="row">-1.6</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   150
         *<tr><th scope="row">-2.5</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   151
         *<tr><th scope="row">-5.5</th> <td>-5</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   152
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    DOWN(BigDecimal.ROUND_DOWN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * Rounding mode to round towards positive infinity.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * result is positive, behaves as for {@code RoundingMode.UP};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * if negative, behaves as for {@code RoundingMode.DOWN}.  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * that this rounding mode never decreases the calculated value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   164
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   165
         * <caption>Rounding mode CEILING Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   166
         *<thead>
44846
b3f9f5bf40b2 8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents: 37784
diff changeset
   167
         *<tr style="vertical-align:top"><th>Input Number</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         *    <th>Input rounded to one digit<br> with {@code CEILING} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   169
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   170
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   171
         *<tr><th scope="row">5.5</th>  <td>6</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   172
         *<tr><th scope="row">2.5</th>  <td>3</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   173
         *<tr><th scope="row">1.6</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   174
         *<tr><th scope="row">1.1</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   175
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   176
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   177
         *<tr><th scope="row">-1.1</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   178
         *<tr><th scope="row">-1.6</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   179
         *<tr><th scope="row">-2.5</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   180
         *<tr><th scope="row">-5.5</th> <td>-5</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   181
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    CEILING(BigDecimal.ROUND_CEILING),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * Rounding mode to round towards negative infinity.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * result is positive, behave as for {@code RoundingMode.DOWN};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * if negative, behave as for {@code RoundingMode.UP}.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * this rounding mode never increases the calculated value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   193
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   194
         * <caption>Rounding mode FLOOR Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   195
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   196
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   197
         *    <th scope="col">Input rounded to one digit<br> with {@code FLOOR} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   198
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   199
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   200
         *<tr><th scope="row">5.5</th>  <td>5</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   201
         *<tr><th scope="row">2.5</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   202
         *<tr><th scope="row">1.6</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   203
         *<tr><th scope="row">1.1</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   204
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   205
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   206
         *<tr><th scope="row">-1.1</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   207
         *<tr><th scope="row">-1.6</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   208
         *<tr><th scope="row">-2.5</th> <td>-3</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   209
         *<tr><th scope="row">-5.5</th> <td>-6</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   210
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    FLOOR(BigDecimal.ROUND_FLOOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * Rounding mode to round towards {@literal "nearest neighbor"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * unless both neighbors are equidistant, in which case round up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         * Behaves as for {@code RoundingMode.UP} if the discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         * fraction is &ge; 0.5; otherwise, behaves as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * {@code RoundingMode.DOWN}.  Note that this is the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         * mode commonly taught at school.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   224
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   225
         * <caption>Rounding mode HALF_UP Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   226
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   227
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   228
         *    <th scope="col">Input rounded to one digit<br> with {@code HALF_UP} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   229
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   230
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   231
         *<tr><th scope="row">5.5</th>  <td>6</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   232
         *<tr><th scope="row">2.5</th>  <td>3</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   233
         *<tr><th scope="row">1.6</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   234
         *<tr><th scope="row">1.1</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   235
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   236
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   237
         *<tr><th scope="row">-1.1</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   238
         *<tr><th scope="row">-1.6</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   239
         *<tr><th scope="row">-2.5</th> <td>-3</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   240
         *<tr><th scope="row">-5.5</th> <td>-6</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   241
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    HALF_UP(BigDecimal.ROUND_HALF_UP),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * Rounding mode to round towards {@literal "nearest neighbor"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         * unless both neighbors are equidistant, in which case round
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
         * down.  Behaves as for {@code RoundingMode.UP} if the discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         * fraction is &gt; 0.5; otherwise, behaves as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * {@code RoundingMode.DOWN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   254
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   255
         * <caption>Rounding mode HALF_DOWN Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   256
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   257
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   258
         *    <th scope="col">Input rounded to one digit<br> with {@code HALF_DOWN} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   259
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   260
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   261
         *<tr><th scope="row">5.5</th>  <td>5</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   262
         *<tr><th scope="row">2.5</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   263
         *<tr><th scope="row">1.6</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   264
         *<tr><th scope="row">1.1</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   265
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   266
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   267
         *<tr><th scope="row">-1.1</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   268
         *<tr><th scope="row">-1.6</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   269
         *<tr><th scope="row">-2.5</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   270
         *<tr><th scope="row">-5.5</th> <td>-5</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   271
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    HALF_DOWN(BigDecimal.ROUND_HALF_DOWN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * Rounding mode to round towards the {@literal "nearest neighbor"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         * unless both neighbors are equidistant, in which case, round
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
         * towards the even neighbor.  Behaves as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
         * {@code RoundingMode.HALF_UP} if the digit to the left of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
         * discarded fraction is odd; behaves as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * {@code RoundingMode.HALF_DOWN} if it's even.  Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         * is the rounding mode that statistically minimizes cumulative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         * error when applied repeatedly over a sequence of calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         * It is sometimes known as {@literal "Banker's rounding,"} and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         * chiefly used in the USA.  This rounding mode is analogous to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         * the rounding policy used for {@code float} and {@code double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * arithmetic in Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   291
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   292
         * <caption>Rounding mode HALF_EVEN Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   293
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   294
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   295
         *    <th scope="col">Input rounded to one digit<br> with {@code HALF_EVEN} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   296
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   297
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   298
         *<tr><th scope="row">5.5</th>  <td>6</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   299
         *<tr><th scope="row">2.5</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   300
         *<tr><th scope="row">1.6</th>  <td>2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   301
         *<tr><th scope="row">1.1</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   302
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   303
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   304
         *<tr><th scope="row">-1.1</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   305
         *<tr><th scope="row">-1.6</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   306
         *<tr><th scope="row">-2.5</th> <td>-2</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   307
         *<tr><th scope="row">-5.5</th> <td>-6</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   308
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    HALF_EVEN(BigDecimal.ROUND_HALF_EVEN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * Rounding mode to assert that the requested operation has an exact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         * result, hence no rounding is necessary.  If this rounding mode is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * specified on an operation that yields an inexact result, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         * {@code ArithmeticException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         *<p>Example:
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   319
         *<table class="striped">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   320
         * <caption>Rounding mode UNNECESSARY Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   321
         *<thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   322
         *<tr style="vertical-align:top"><th scope="col">Input Number</th>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   323
         *    <th scope="col">Input rounded to one digit<br> with {@code UNNECESSARY} rounding
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   324
         *</thead>
46149
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   325
         *<tbody style="text-align:right">
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   326
         *<tr><th scope="row">5.5</th>  <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   327
         *<tr><th scope="row">2.5</th>  <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   328
         *<tr><th scope="row">1.6</th>  <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   329
         *<tr><th scope="row">1.1</th>  <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   330
         *<tr><th scope="row">1.0</th>  <td>1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   331
         *<tr><th scope="row">-1.0</th> <td>-1</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   332
         *<tr><th scope="row">-1.1</th> <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   333
         *<tr><th scope="row">-1.6</th> <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   334
         *<tr><th scope="row">-2.5</th> <td>throw {@code ArithmeticException}</td>
b515ebc3db98 8186153: Fix a11y and HTML issues in the java.math, java.text and java.time packages
jjg
parents: 45124
diff changeset
   335
         *<tr><th scope="row">-5.5</th> <td>throw {@code ArithmeticException}</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   336
         *</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         *</table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    UNNECESSARY(BigDecimal.ROUND_UNNECESSARY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    // Corresponding BigDecimal rounding constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    final int oldMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @param oldMode The {@code BigDecimal} constant corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *        this mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    private RoundingMode(int oldMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        this.oldMode = oldMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Returns the {@code RoundingMode} object corresponding to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * legacy integer rounding mode constant in {@link BigDecimal}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param  rm legacy integer rounding mode to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return {@code RoundingMode} corresponding to the given integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @throws IllegalArgumentException integer is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public static RoundingMode valueOf(int rm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        switch(rm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        case BigDecimal.ROUND_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        case BigDecimal.ROUND_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        case BigDecimal.ROUND_CEILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            return CEILING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        case BigDecimal.ROUND_FLOOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            return FLOOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        case BigDecimal.ROUND_HALF_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return HALF_UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        case BigDecimal.ROUND_HALF_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return HALF_DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        case BigDecimal.ROUND_HALF_EVEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return HALF_EVEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        case BigDecimal.ROUND_UNNECESSARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return UNNECESSARY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throw new IllegalArgumentException("argument out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
}