< prev index next >

src/java.base/share/classes/java/math/RoundingMode.java

Print this page

        

*** 49,85 **** * {@code roundingMode} set to the rounding mode in question), and * calling {@link BigDecimal#round round} on this number with the * proper {@code MathContext}. A summary table showing the results * of these rounding operations for all rounding modes appears below. * ! *<table class="plain"> * <caption><b>Summary of Rounding Operations Under Different Rounding Modes</b></caption> * <thead> ! * <tr><th></th><th colspan=8>Result of rounding input to one digit with the given * rounding mode</th> * <tr style="vertical-align:top"> ! * <th>Input Number</th> <th>{@code UP}</th> * <th>{@code DOWN}</th> * <th>{@code CEILING}</th> * <th>{@code FLOOR}</th> * <th>{@code HALF_UP}</th> * <th>{@code HALF_DOWN}</th> * <th>{@code HALF_EVEN}</th> * <th>{@code UNNECESSARY}</th> * </thead> ! * <tbody> * ! * <tr style="text-align:right"><td>5.5</td> <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> ! * <tr style="text-align:right"><td>2.5</td> <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> ! * <tr style="text-align:right"><td>1.6</td> <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> ! * <tr style="text-align:right"><td>1.1</td> <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> ! * <tr style="text-align:right"><td>1.0</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> ! * <tr style="text-align:right"><td>-1.0</td> <td>-1</td> <td>-1</td> <td>-1</td> <td>-1</td> <td>-1</td> <td>-1</td> <td>-1</td> <td>-1</td> ! * <tr style="text-align:right"><td>-1.1</td> <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> ! * <tr style="text-align:right"><td>-1.6</td> <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> ! * <tr style="text-align:right"><td>-2.5</td> <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> ! * <tr style="text-align:right"><td>-5.5</td> <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> * </tbody> * </table> * * * <p>This {@code enum} is intended to replace the integer-based --- 49,85 ---- * {@code roundingMode} set to the rounding mode in question), and * calling {@link BigDecimal#round round} on this number with the * proper {@code MathContext}. A summary table showing the results * of these rounding operations for all rounding modes appears below. * ! *<table class="striped"> * <caption><b>Summary of Rounding Operations Under Different Rounding Modes</b></caption> * <thead> ! * <tr><th scope="col" rowspan="2">Input Number</th><th scope="col"colspan=8>Result of rounding input to one digit with the given * rounding mode</th> * <tr style="vertical-align:top"> ! * <th>{@code UP}</th> * <th>{@code DOWN}</th> * <th>{@code CEILING}</th> * <th>{@code FLOOR}</th> * <th>{@code HALF_UP}</th> * <th>{@code HALF_DOWN}</th> * <th>{@code HALF_EVEN}</th> * <th>{@code UNNECESSARY}</th> * </thead> ! * <tbody style="text-align:right"> * ! * <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> ! * <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> ! * <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> ! * <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> ! * <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> ! * <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> ! * <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> ! * <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> ! * <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> ! * <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> * </tbody> * </table> * * * <p>This {@code enum} is intended to replace the integer-based
*** 102,128 **** * digit prior to a non-zero discarded fraction. Note that this * rounding mode never decreases the magnitude of the calculated * value. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode UP Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code UP} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>6</td> ! *<tr style="text-align:right"><td>2.5</td> <td>3</td> ! *<tr style="text-align:right"><td>1.6</td> <td>2</td> ! *<tr style="text-align:right"><td>1.1</td> <td>2</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-2</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-2</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-3</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-6</td> *</tbody> *</table> */ UP(BigDecimal.ROUND_UP), --- 102,128 ---- * digit prior to a non-zero discarded fraction. Note that this * rounding mode never decreases the magnitude of the calculated * value. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode UP Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code UP} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>6</td> ! *<tr><th scope="row">2.5</th> <td>3</td> ! *<tr><th scope="row">1.6</th> <td>2</td> ! *<tr><th scope="row">1.1</th> <td>2</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-2</td> ! *<tr><th scope="row">-1.6</th> <td>-2</td> ! *<tr><th scope="row">-2.5</th> <td>-3</td> ! *<tr><th scope="row">-5.5</th> <td>-6</td> *</tbody> *</table> */ UP(BigDecimal.ROUND_UP),
*** 130,156 **** * Rounding mode to round towards zero. Never increments the digit * prior to a discarded fraction (i.e., truncates). Note that this * rounding mode never increases the magnitude of the calculated value. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode DOWN Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code DOWN} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>5</td> ! *<tr style="text-align:right"><td>2.5</td> <td>2</td> ! *<tr style="text-align:right"><td>1.6</td> <td>1</td> ! *<tr style="text-align:right"><td>1.1</td> <td>1</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-1</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-2</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-5</td> *</tbody> *</table> */ DOWN(BigDecimal.ROUND_DOWN), --- 130,156 ---- * Rounding mode to round towards zero. Never increments the digit * prior to a discarded fraction (i.e., truncates). Note that this * rounding mode never increases the magnitude of the calculated value. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode DOWN Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code DOWN} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>5</td> ! *<tr><th scope="row">2.5</th> <td>2</td> ! *<tr><th scope="row">1.6</th> <td>1</td> ! *<tr><th scope="row">1.1</th> <td>1</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-1</td> ! *<tr><th scope="row">-1.6</th> <td>-1</td> ! *<tr><th scope="row">-2.5</th> <td>-2</td> ! *<tr><th scope="row">-5.5</th> <td>-5</td> *</tbody> *</table> */ DOWN(BigDecimal.ROUND_DOWN),
*** 159,185 **** * result is positive, behaves as for {@code RoundingMode.UP}; * if negative, behaves as for {@code RoundingMode.DOWN}. Note * that this rounding mode never decreases the calculated value. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode CEILING Examples</b></caption> *<thead> *<tr style="vertical-align:top"><th>Input Number</th> * <th>Input rounded to one digit<br> with {@code CEILING} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>6</td> ! *<tr style="text-align:right"><td>2.5</td> <td>3</td> ! *<tr style="text-align:right"><td>1.6</td> <td>2</td> ! *<tr style="text-align:right"><td>1.1</td> <td>2</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-1</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-2</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-5</td> *</tbody> *</table> */ CEILING(BigDecimal.ROUND_CEILING), --- 159,185 ---- * result is positive, behaves as for {@code RoundingMode.UP}; * if negative, behaves as for {@code RoundingMode.DOWN}. Note * that this rounding mode never decreases the calculated value. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode CEILING Examples</caption> *<thead> *<tr style="vertical-align:top"><th>Input Number</th> * <th>Input rounded to one digit<br> with {@code CEILING} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>6</td> ! *<tr><th scope="row">2.5</th> <td>3</td> ! *<tr><th scope="row">1.6</th> <td>2</td> ! *<tr><th scope="row">1.1</th> <td>2</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-1</td> ! *<tr><th scope="row">-1.6</th> <td>-1</td> ! *<tr><th scope="row">-2.5</th> <td>-2</td> ! *<tr><th scope="row">-5.5</th> <td>-5</td> *</tbody> *</table> */ CEILING(BigDecimal.ROUND_CEILING),
*** 188,214 **** * result is positive, behave as for {@code RoundingMode.DOWN}; * if negative, behave as for {@code RoundingMode.UP}. Note that * this rounding mode never increases the calculated value. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode FLOOR Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code FLOOR} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>5</td> ! *<tr style="text-align:right"><td>2.5</td> <td>2</td> ! *<tr style="text-align:right"><td>1.6</td> <td>1</td> ! *<tr style="text-align:right"><td>1.1</td> <td>1</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-2</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-2</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-3</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-6</td> *</tbody> *</table> */ FLOOR(BigDecimal.ROUND_FLOOR), --- 188,214 ---- * result is positive, behave as for {@code RoundingMode.DOWN}; * if negative, behave as for {@code RoundingMode.UP}. Note that * this rounding mode never increases the calculated value. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode FLOOR Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code FLOOR} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>5</td> ! *<tr><th scope="row">2.5</th> <td>2</td> ! *<tr><th scope="row">1.6</th> <td>1</td> ! *<tr><th scope="row">1.1</th> <td>1</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-2</td> ! *<tr><th scope="row">-1.6</th> <td>-2</td> ! *<tr><th scope="row">-2.5</th> <td>-3</td> ! *<tr><th scope="row">-5.5</th> <td>-6</td> *</tbody> *</table> */ FLOOR(BigDecimal.ROUND_FLOOR),
*** 219,245 **** * fraction is &ge; 0.5; otherwise, behaves as for * {@code RoundingMode.DOWN}. Note that this is the rounding * mode commonly taught at school. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode HALF_UP Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code HALF_UP} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>6</td> ! *<tr style="text-align:right"><td>2.5</td> <td>3</td> ! *<tr style="text-align:right"><td>1.6</td> <td>2</td> ! *<tr style="text-align:right"><td>1.1</td> <td>1</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-2</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-3</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-6</td> *</tbody> *</table> */ HALF_UP(BigDecimal.ROUND_HALF_UP), --- 219,245 ---- * fraction is &ge; 0.5; otherwise, behaves as for * {@code RoundingMode.DOWN}. Note that this is the rounding * mode commonly taught at school. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode HALF_UP Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code HALF_UP} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>6</td> ! *<tr><th scope="row">2.5</th> <td>3</td> ! *<tr><th scope="row">1.6</th> <td>2</td> ! *<tr><th scope="row">1.1</th> <td>1</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-1</td> ! *<tr><th scope="row">-1.6</th> <td>-2</td> ! *<tr><th scope="row">-2.5</th> <td>-3</td> ! *<tr><th scope="row">-5.5</th> <td>-6</td> *</tbody> *</table> */ HALF_UP(BigDecimal.ROUND_HALF_UP),
*** 249,275 **** * down. Behaves as for {@code RoundingMode.UP} if the discarded * fraction is &gt; 0.5; otherwise, behaves as for * {@code RoundingMode.DOWN}. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode HALF_DOWN Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code HALF_DOWN} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>5</td> ! *<tr style="text-align:right"><td>2.5</td> <td>2</td> ! *<tr style="text-align:right"><td>1.6</td> <td>2</td> ! *<tr style="text-align:right"><td>1.1</td> <td>1</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-2</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-2</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-5</td> *</tbody> *</table> */ HALF_DOWN(BigDecimal.ROUND_HALF_DOWN), --- 249,275 ---- * down. Behaves as for {@code RoundingMode.UP} if the discarded * fraction is &gt; 0.5; otherwise, behaves as for * {@code RoundingMode.DOWN}. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode HALF_DOWN Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code HALF_DOWN} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>5</td> ! *<tr><th scope="row">2.5</th> <td>2</td> ! *<tr><th scope="row">1.6</th> <td>2</td> ! *<tr><th scope="row">1.1</th> <td>1</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-1</td> ! *<tr><th scope="row">-1.6</th> <td>-2</td> ! *<tr><th scope="row">-2.5</th> <td>-2</td> ! *<tr><th scope="row">-5.5</th> <td>-5</td> *</tbody> *</table> */ HALF_DOWN(BigDecimal.ROUND_HALF_DOWN),
*** 286,312 **** * chiefly used in the USA. This rounding mode is analogous to * the rounding policy used for {@code float} and {@code double} * arithmetic in Java. * *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode HALF_EVEN Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code HALF_EVEN} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>6</td> ! *<tr style="text-align:right"><td>2.5</td> <td>2</td> ! *<tr style="text-align:right"><td>1.6</td> <td>2</td> ! *<tr style="text-align:right"><td>1.1</td> <td>1</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>-2</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>-2</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>-6</td> *</tbody> *</table> */ HALF_EVEN(BigDecimal.ROUND_HALF_EVEN), --- 286,312 ---- * chiefly used in the USA. This rounding mode is analogous to * the rounding policy used for {@code float} and {@code double} * arithmetic in Java. * *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode HALF_EVEN Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code HALF_EVEN} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>6</td> ! *<tr><th scope="row">2.5</th> <td>2</td> ! *<tr><th scope="row">1.6</th> <td>2</td> ! *<tr><th scope="row">1.1</th> <td>1</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>-1</td> ! *<tr><th scope="row">-1.6</th> <td>-2</td> ! *<tr><th scope="row">-2.5</th> <td>-2</td> ! *<tr><th scope="row">-5.5</th> <td>-6</td> *</tbody> *</table> */ HALF_EVEN(BigDecimal.ROUND_HALF_EVEN),
*** 314,340 **** * Rounding mode to assert that the requested operation has an exact * result, hence no rounding is necessary. If this rounding mode is * specified on an operation that yields an inexact result, an * {@code ArithmeticException} is thrown. *<p>Example: ! *<table class="plain"> ! * <caption><b>Rounding mode UNNECESSARY Examples</b></caption> *<thead> ! *<tr style="vertical-align:top"><th>Input Number</th> ! * <th>Input rounded to one digit<br> with {@code UNNECESSARY} rounding *</thead> ! *<tbody> ! *<tr style="text-align:right"><td>5.5</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>2.5</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>1.6</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>1.1</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>1.0</td> <td>1</td> ! *<tr style="text-align:right"><td>-1.0</td> <td>-1</td> ! *<tr style="text-align:right"><td>-1.1</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>-1.6</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>-2.5</td> <td>throw {@code ArithmeticException}</td> ! *<tr style="text-align:right"><td>-5.5</td> <td>throw {@code ArithmeticException}</td> *</tbody> *</table> */ UNNECESSARY(BigDecimal.ROUND_UNNECESSARY); --- 314,340 ---- * Rounding mode to assert that the requested operation has an exact * result, hence no rounding is necessary. If this rounding mode is * specified on an operation that yields an inexact result, an * {@code ArithmeticException} is thrown. *<p>Example: ! *<table class="striped"> ! * <caption>Rounding mode UNNECESSARY Examples</caption> *<thead> ! *<tr style="vertical-align:top"><th scope="col">Input Number</th> ! * <th scope="col">Input rounded to one digit<br> with {@code UNNECESSARY} rounding *</thead> ! *<tbody style="text-align:right"> ! *<tr><th scope="row">5.5</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">2.5</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">1.6</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">1.1</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">1.0</th> <td>1</td> ! *<tr><th scope="row">-1.0</th> <td>-1</td> ! *<tr><th scope="row">-1.1</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">-1.6</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">-2.5</th> <td>throw {@code ArithmeticException}</td> ! *<tr><th scope="row">-5.5</th> <td>throw {@code ArithmeticException}</td> *</tbody> *</table> */ UNNECESSARY(BigDecimal.ROUND_UNNECESSARY);
< prev index next >