net.sf.morph.transform.support
Class NumberRounder

java.lang.Object
  extended by net.sf.morph.transform.support.NumberRounder

public abstract class NumberRounder
extends java.lang.Object

Since:
Dec 15, 2004
Author:
Matt Sgarlata

Field Summary
static java.lang.String ROUND_CEILING
          Rounding mode specified in BigDecimal.
static java.lang.String ROUND_DOWN
          Rounding mode specified in BigDecimal.
static java.lang.String ROUND_FLOOR
          Rounding mode specified in BigDecimal.
static java.lang.String ROUND_HALF_DOWN
          Rounding mode specified in BigDecimal.
static java.lang.String ROUND_HALF_EVEN
          Rounding mode specified in BigDecimal.
static java.lang.String ROUND_HALF_UP
          Rounding mode specified in BigDecimal.
static java.lang.String ROUND_UP
          Rounding mode specified in BigDecimal.
 
Constructor Summary
NumberRounder()
           
 
Method Summary
static int getBigDecimalRoundMode(java.lang.String mode)
          Converts a rounding mode defined in this class to one of the rounding mode ints specified in the BigDecimal class.
static java.lang.Number round(java.lang.Number number, java.lang.String mode)
          Rounds the given number using the given rounding mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROUND_CEILING

public static final java.lang.String ROUND_CEILING
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_CEILING, Constant Field Values

ROUND_DOWN

public static final java.lang.String ROUND_DOWN
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_DOWN, Constant Field Values

ROUND_FLOOR

public static final java.lang.String ROUND_FLOOR
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_FLOOR, Constant Field Values

ROUND_HALF_DOWN

public static final java.lang.String ROUND_HALF_DOWN
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_HALF_DOWN, Constant Field Values

ROUND_HALF_EVEN

public static final java.lang.String ROUND_HALF_EVEN
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_HALF_EVEN, Constant Field Values

ROUND_HALF_UP

public static final java.lang.String ROUND_HALF_UP
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_HALF_UP, Constant Field Values

ROUND_UP

public static final java.lang.String ROUND_UP
Rounding mode specified in BigDecimal.

See Also:
BigDecimal.ROUND_UP, Constant Field Values
Constructor Detail

NumberRounder

public NumberRounder()
Method Detail

getBigDecimalRoundMode

public static int getBigDecimalRoundMode(java.lang.String mode)
                                  throws java.lang.IllegalArgumentException
Converts a rounding mode defined in this class to one of the rounding mode ints specified in the BigDecimal class.

Parameters:
mode - the String representation of the mode, as defined in one of the constants of this class
Returns:
the int representation of the mode, as defined in the BigDecimal class.
Throws:
java.lang.IllegalArgumentException - if an invalid rounding mode was specified

round

public static java.lang.Number round(java.lang.Number number,
                                     java.lang.String mode)
                              throws java.lang.IllegalArgumentException
Rounds the given number using the given rounding mode. The type of the number is maintained (e.g. - if the number was a Float, it will remain so).

Parameters:
number - the number to round
mode - the rounding mode, as specified by one of the constants in this class
Returns:
null, if number is null or
number rounded as requested, otherwise
Throws:
java.lang.IllegalArgumentException - if an invalid rounding mode is specified


Copyright © 2004-2008.