Constants Summary | ||
---|---|---|
public
int
|
UNNECESSARY
Asserts that the requested operation has an exact result, hence no rounding is necessary.
If this rounding mode is specified on an operation that yields a result that
cannot be represented at the requested scale, a RoundingNecessaryException is thrown.
|
#
0
|
public
int
|
UP
Rounds away from zero.
Always increments the digit prior to a nonzero discarded fraction.
Note that this rounding mode never decreases the magnitude of the calculated value.
|
#
1
|
public
int
|
DOWN
Rounds 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.
|
#
2
|
public
int
|
CEILING
Rounds towards positive infinity.
If the result is positive, behaves as for UP; if negative, behaves as for DOWN.
Note that this rounding mode never decreases the calculated value.
|
#
3
|
public
int
|
FLOOR
Rounds towards negative infinity.
If the result is positive, behave as for DOWN; if negative, behave as for UP.
Note that this rounding mode never increases the calculated value.
|
#
4
|
public
int
|
HALF_UP
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves as for DOWN.
Note that this is the rounding mode commonly taught at school.
|
#
5
|
public
int
|
HALF_DOWN
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN.
|
#
6
|
public
int
|
HALF_CEILING
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity.
If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN.
|
#
7
|
public
int
|
HALF_FLOOR
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity.
If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP.
|
#
8
|
public
int
|
HALF_EVEN
Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor.
Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd;
behaves as for 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 "Banker's rounding", and is chiefly used in the USA.
|
#
9
|