RoundingMode

Undocumented in source.

Members

Functions

mode
int mode()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

valueOf
RoundingMode valueOf(int rm)

Returns the {@code RoundingMode} object corresponding to a legacy integer rounding mode constant in {@link BigDecimal}.

Static variables

CEILING
RoundingMode CEILING;

Rounding mode to round towards positive infinity. If the 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.

DOWN
RoundingMode DOWN;

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.

FLOOR
RoundingMode FLOOR;

Rounding mode to round towards negative infinity. If the 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.

HALF_DOWN
RoundingMode HALF_DOWN;

Rounding mode to round towards {@literal "nearest neighbor"} unless both neighbors are equidistant, in which case round down. Behaves as for {@code RoundingMode.UP} if the discarded fraction is > 0.5; otherwise, behaves as for {@code RoundingMode.DOWN}.

HALF_EVEN
RoundingMode HALF_EVEN;

Rounding mode to round towards the {@literal "nearest neighbor"} unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for {@code RoundingMode.HALF_UP} if the digit to the left of the discarded fraction is odd; behaves as for {@code RoundingMode.HALF_DOWN} if it's even. Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as {@literal "Banker's rounding,"} and is chiefly used in the USA. This rounding mode is analogous to the rounding policy used for {@code float} and {@code double} arithmetic in Java.

HALF_UP
RoundingMode HALF_UP;

Rounding mode to round towards {@literal "nearest neighbor"} unless both neighbors are equidistant, in which case round up. Behaves as for {@code RoundingMode.UP} if the discarded fraction is ≥ 0.5; otherwise, behaves as for {@code RoundingMode.DOWN}. Note that this is the rounding mode commonly taught at school.

UNNECESSARY
RoundingMode UNNECESSARY;

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> <tr align=right><td>1.6</td> <td>throw {@code ArithmeticException}</td> <tr align=right><td>1.1</td> <td>throw {@code ArithmeticException}</td> <tr align=right><td>1.0</td> <td>1</td> <tr align=right><td>-1.0</td> <td>-1</td> <tr align=right><td>-1.1</td> <td>throw {@code ArithmeticException}</td> <tr align=right><td>-1.6</td> <td>throw {@code ArithmeticException}</td> <tr align=right><td>-2.5</td> <td>throw {@code ArithmeticException}</td> <tr align=right><td>-5.5</td> <td>throw {@code ArithmeticException}</td> </table>

UP
RoundingMode UP;

Rounding mode to round away from zero. Always increments the digit prior to a non-zero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.

Variables

oldMode
int oldMode;
Undocumented in source.

Meta