public enum CheckedRounding extends Enum<CheckedRounding> implements TruncationPolicy
TruncationPolicy
for
OverflowMode.CHECKED
. The constants are equivalent to the constants
defined by RoundingMode
; the policy's getOverflowMode()
method always returns CHECKED
overflow mode.Enum Constant and Description |
---|
CEILING
Checked truncation policy with rounding mode to round towards positive
infinity.
|
DOWN
Checked truncation policy with rounding mode to round towards zero.
|
FLOOR
Checked truncation policy with rounding mode to round towards negative
infinity.
|
HALF_DOWN
Checked truncation policy with rounding mode to round towards
"nearest neighbor" unless both neighbors are equidistant, in
which case round down.
|
HALF_EVEN
Checked truncation policy with rounding mode to round towards the
"nearest neighbor" unless both neighbors are equidistant, in
which case, round towards the even neighbor.
|
HALF_UP
Checked truncation policy with rounding mode to round towards
"nearest neighbor" unless both neighbors are equidistant, in
which case round up.
|
UNNECESSARY
Checked truncation policy with rounding mode to assert that the requested
operation has an exact result, hence no rounding is necessary.
|
UP
Checked truncation policy with rounding mode to round away from zero.
|
Modifier and Type | Field and Description |
---|---|
static Set<CheckedRounding> |
VALUES
Immutable set with all values of this enum.
|
DEFAULT
Modifier and Type | Method and Description |
---|---|
OverflowMode |
getOverflowMode()
Returns
OverflowMode.CHECKED . |
String |
toString()
Returns "CHECKED/(name)" where
(name) stands for the Enum.name() of this constant. |
abstract UncheckedRounding |
toUncheckedRounding()
Returns the policy with the same
rounding mode
as this checked rounding policy but for UNCHECKED overflow mode . |
static CheckedRounding |
valueOf(RoundingMode roundingMode)
Returns the checked rounding constant for the given rounding mode.
|
static CheckedRounding |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static CheckedRounding[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
getRoundingMode
public static final CheckedRounding UP
RoundingMode.UP
public static final CheckedRounding DOWN
RoundingMode.DOWN
public static final CheckedRounding CEILING
RoundingMode.UP
; if negative, behaves as for
RoundingMode.DOWN
. Note that this rounding mode never decreases
the calculated value.RoundingMode.CEILING
public static final CheckedRounding FLOOR
RoundingMode.DOWN
; if negative, behave as for
RoundingMode.UP
. Note that this rounding mode never increases the
calculated value.RoundingMode.FLOOR
public static final CheckedRounding HALF_UP
RoundingMode.UP
if the
discarded fraction is ≥ 0.5; otherwise, behaves as for
RoundingMode.DOWN
. Note that this is the rounding mode commonly
taught at school.RoundingMode.HALF_UP
public static final CheckedRounding HALF_DOWN
RoundingMode.UP
if the
discarded fraction is > 0.5; otherwise, behaves as for
RoundingMode.DOWN
.RoundingMode.HALF_DOWN
public static final CheckedRounding HALF_EVEN
RoundingMode.HALF_UP
if the digit to the left of the discarded
fraction is odd; behaves as for 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 "Banker's rounding," and is chiefly
used in the USA. This rounding mode is analogous to the rounding policy
used for float
and double
arithmetic in Java.RoundingMode.HALF_EVEN
public static final CheckedRounding UNNECESSARY
ArithmeticException
is thrown.RoundingMode.UNNECESSARY
public static final Set<CheckedRounding> VALUES
values()
.public static CheckedRounding[] values()
for (CheckedRounding c : CheckedRounding.values()) System.out.println(c);
public static CheckedRounding valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic final OverflowMode getOverflowMode()
OverflowMode.CHECKED
.getOverflowMode
in interface TruncationPolicy
public abstract UncheckedRounding toUncheckedRounding()
rounding mode
as this checked rounding policy but for UNCHECKED
overflow mode
.UncheckedRounding
counterpart to this policy.public final String toString()
(name)
stands for the Enum.name()
of this constant.toString
in class Enum<CheckedRounding>
public static final CheckedRounding valueOf(RoundingMode roundingMode)
roundingMode
- the rounding mode