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 failsthat is, if the operation does require roundingan ArithmeticException is thrown. Figure 11-4. java.math.RoundingModepublic 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 ToBigDecimal.{divide( ) , setScale( )} , MathContext.MathContext( ) Returned ByMathContext.getRoundingMode( ) |