Name
RoundingMode
Synopsis
The
constants
defined by this enumerated type represent possible ways of rounding
numbers. UP and DOWN specify
rounding away from zero or toward zero. CEILING
and FLOOR represent rounding toward positive
infinity and negative infinity. HALF_UP,
HALF_DOWN, and HALF_EVEN all
round toward the nearest value and differ only in what they do when
two values are equidistant. In this case, they round up, down, or to
the “even” neighbor.
UNNECESSARY is a special rounding mode that serves
as an assertion that an arithmetic operation will have an exact
result and that rounding is not needed. If this assertion
fails—that is, if the operation does require rounding—an
ArithmeticException is thrown.
Figure 11-4. java.math.RoundingMode
public enum RoundingMode { // Enumerated Constants UP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN, HALF_EVEN, UNNECESSARY; // Public Class Methods public static RoundingMode valueOf(int rm); public static RoundingMode valueOf(String name); public static final RoundingMode[ ] values( ); }
Passed To
BigDecimal.{divide( ), setScale(
)}, MathContext.MathContext( )
Returned By
MathContext.getRoundingMode( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access