RoundingMode


RoundingMode java.math

Java 5.0 serializable comparable enum

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.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( )



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net