src/share/classes/java/math/RoundingMode.java
Print this page
*** 49,59 ****
* {@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 border>
* <caption><b>Summary of Rounding Operations Under Different Rounding Modes</b></caption>
* <tr><th></th><th colspan=8>Result of rounding input to one digit with the given
* rounding mode</th>
* <tr valign=top>
* <th>Input Number</th> <th>{@code UP}</th>
--- 49,59 ----
* {@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 border summary="Summary of rounding operations">
* <caption><b>Summary of Rounding Operations Under Different Rounding Modes</b></caption>
* <tr><th></th><th colspan=8>Result of rounding input to one digit with the given
* rounding mode</th>
* <tr valign=top>
* <th>Input Number</th> <th>{@code UP}</th>
*** 97,107 ****
* digit prior to a non-zero discarded fraction. Note that this
* rounding mode never decreases the magnitude of the calculated
* value.
*
*<p>Example:
! *<table border>
* <caption><b>Rounding mode UP Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code UP} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>3</td>
--- 97,107 ----
* digit prior to a non-zero discarded fraction. Note that this
* rounding mode never decreases the magnitude of the calculated
* value.
*
*<p>Example:
! *<table border summary="Rounding mode UP examples">
* <caption><b>Rounding mode UP Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code UP} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>3</td>
*** 121,131 ****
* 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 border>
* <caption><b>Rounding mode DOWN Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code DOWN} rounding
*<tr align=right><td>5.5</td> <td>5</td>
*<tr align=right><td>2.5</td> <td>2</td>
--- 121,131 ----
* 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 border summary="Rounding mode DOWN examples">
* <caption><b>Rounding mode DOWN Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code DOWN} rounding
*<tr align=right><td>5.5</td> <td>5</td>
*<tr align=right><td>2.5</td> <td>2</td>
*** 146,156 ****
* 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 border>
* <caption><b>Rounding mode CEILING Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code CEILING} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>3</td>
--- 146,156 ----
* 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 border summary="Rounding mode CEILING examples">
* <caption><b>Rounding mode CEILING Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code CEILING} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>3</td>
*** 171,181 ****
* 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 border>
* <caption><b>Rounding mode FLOOR Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code FLOOR} rounding
*<tr align=right><td>5.5</td> <td>5</td>
*<tr align=right><td>2.5</td> <td>2</td>
--- 171,181 ----
* 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 border summary="Rounding mode FLOOR examples">
* <caption><b>Rounding mode FLOOR Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code FLOOR} rounding
*<tr align=right><td>5.5</td> <td>5</td>
*<tr align=right><td>2.5</td> <td>2</td>
*** 198,208 ****
* fraction is ≥ 0.5; otherwise, behaves as for
* {@code RoundingMode.DOWN}. Note that this is the rounding
* mode commonly taught at school.
*
*<p>Example:
! *<table border>
* <caption><b>Rounding mode HALF_UP Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code HALF_UP} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>3</td>
--- 198,208 ----
* fraction is ≥ 0.5; otherwise, behaves as for
* {@code RoundingMode.DOWN}. Note that this is the rounding
* mode commonly taught at school.
*
*<p>Example:
! *<table border summary="Rounding mode HALF_UP examples">
* <caption><b>Rounding mode HALF_UP Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code HALF_UP} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>3</td>
*** 224,234 ****
* down. Behaves as for {@code RoundingMode.UP} if the discarded
* fraction is > 0.5; otherwise, behaves as for
* {@code RoundingMode.DOWN}.
*
*<p>Example:
! *<table border>
* <caption><b>Rounding mode HALF_DOWN Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code HALF_DOWN} rounding
*<tr align=right><td>5.5</td> <td>5</td>
*<tr align=right><td>2.5</td> <td>2</td>
--- 224,234 ----
* down. Behaves as for {@code RoundingMode.UP} if the discarded
* fraction is > 0.5; otherwise, behaves as for
* {@code RoundingMode.DOWN}.
*
*<p>Example:
! *<table border summary="Rounding mode HALF_DOWN examples">
* <caption><b>Rounding mode HALF_DOWN Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code HALF_DOWN} rounding
*<tr align=right><td>5.5</td> <td>5</td>
*<tr align=right><td>2.5</td> <td>2</td>
*** 257,267 ****
* 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 border>
* <caption><b>Rounding mode HALF_EVEN Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code HALF_EVEN} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>2</td>
--- 257,267 ----
* 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 border summary="Rounding mode HALF_EVEN examples">
* <caption><b>Rounding mode HALF_EVEN Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code HALF_EVEN} rounding
*<tr align=right><td>5.5</td> <td>6</td>
*<tr align=right><td>2.5</td> <td>2</td>
*** 281,291 ****
* 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 border>
* <caption><b>Rounding mode UNNECESSARY Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code UNNECESSARY} rounding
*<tr align=right><td>5.5</td> <td>throw {@code ArithmeticException}</td>
*<tr align=right><td>2.5</td> <td>throw {@code ArithmeticException}</td>
--- 281,291 ----
* 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 border summary="Rounding mode UNNECESSARY examples">
* <caption><b>Rounding mode UNNECESSARY Examples</b></caption>
*<tr valign=top><th>Input Number</th>
* <th>Input rounded to one digit<br> with {@code UNNECESSARY} rounding
*<tr align=right><td>5.5</td> <td>throw {@code ArithmeticException}</td>
*<tr align=right><td>2.5</td> <td>throw {@code ArithmeticException}</td>