org.zkoss.math
Class BigDecimals

java.lang.Object
  extended by org.zkoss.math.BigDecimals

public class BigDecimals
extends Object

Utilities and constants of big decimals.

Author:
tomyeh

Field Summary
static int FINE_NUMBER_PRECISION
          Represents our fine number precision.
static int FINE_NUMBER_SCALE
          Represents our fine number scale.
static BigDecimal MINUS_ONE
          Represents -1 in big decimal.
static int NUMBER_PRECISION
          Represents our number precision.
static int NUMBER_SCALE
          Represents our number scale.
static BigDecimal ONE
          Represents 1 in big decimal.
static BigDecimal ZERO
          Represents 0 in big decimal.
 
Constructor Summary
BigDecimals()
           
 
Method Summary
static BigDecimal toBigDecimal(byte v)
          Converts a byte to a big decimal with a scale without.
static BigDecimal toBigDecimal(Byte v)
          Converts a byte to a big decimal with a scale without.
static BigDecimal toBigDecimal(double v, int scale)
          Converts a double to a big decimal with a scale.
static BigDecimal toBigDecimal(double v, int scale, int roundingMode)
          Converts a double to a big decimal with a scale.
static BigDecimal toBigDecimal(int v)
          Converts an integer to a big decimal with a scale without.
static BigDecimal toBigDecimal(Integer v)
          Converts an integer to a big decimal with a scale without.
static BigDecimal toBigDecimal(int v, int scale)
          Converts an integer to a big decimal with a scale.
static BigDecimal toBigDecimal(long v)
          Converts a long to a big decimal with a scale without.
static BigDecimal toBigDecimal(Long v)
          Converts a long to a big decimal with a scale without.
static BigDecimal toBigDecimal(long v, int scale)
          Converts an integer to a big decimal with a scale.
static BigDecimal toBigDecimal(short v)
          Converts a short to a big decimal with a scale without.
static BigDecimal toBigDecimal(Short v)
          Converts a short to a big decimal with a scale without.
static String toPlainString(BigDecimal bd)
          Returns a string representation of this BigDecimal without an exponent field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static final BigDecimal ZERO
Represents 0 in big decimal.

See Also:
ONE, MINUS_ONE

ONE

public static final BigDecimal ONE
Represents 1 in big decimal.

See Also:
ZERO, MINUS_ONE

MINUS_ONE

public static final BigDecimal MINUS_ONE
Represents -1 in big decimal.

See Also:
ZERO, ONE

NUMBER_PRECISION

public static final int NUMBER_PRECISION
Represents our number precision.

See Also:
Constant Field Values

NUMBER_SCALE

public static final int NUMBER_SCALE
Represents our number scale.

See Also:
Constant Field Values

FINE_NUMBER_PRECISION

public static final int FINE_NUMBER_PRECISION
Represents our fine number precision.

See Also:
Constant Field Values

FINE_NUMBER_SCALE

public static final int FINE_NUMBER_SCALE
Represents our fine number scale.

See Also:
Constant Field Values
Constructor Detail

BigDecimals

public BigDecimals()
Method Detail

toBigDecimal

public static final BigDecimal toBigDecimal(double v,
                                            int scale,
                                            int roundingMode)
Converts a double to a big decimal with a scale.

It is strongly deprecated to use new Dicimal(double) since the scale is unpredictable and usually surprising. Example, BigDecimal(.1) will becomes .1000000000000000055511151231257827021181583404541015625. On the other hand, BigDecimal("0.1") will be 0.1 correctly.

Parameters:
scale - the BigDecimal's scale
roundingMode - the rounding mode

toBigDecimal

public static final BigDecimal toBigDecimal(double v,
                                            int scale)
Converts a double to a big decimal with a scale. It uses BigDecimal.ROUND_HALF_UP.


toBigDecimal

public static final BigDecimal toBigDecimal(int v,
                                            int scale)
Converts an integer to a big decimal with a scale.


toBigDecimal

public static final BigDecimal toBigDecimal(long v,
                                            int scale)
Converts an integer to a big decimal with a scale.


toBigDecimal

public static final BigDecimal toBigDecimal(int v)
Converts an integer to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(long v)
Converts a long to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(short v)
Converts a short to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(byte v)
Converts a byte to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(Integer v)
Converts an integer to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(Long v)
Converts a long to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(Short v)
Converts a short to a big decimal with a scale without. losing precision -- zero scale in this case.


toBigDecimal

public static final BigDecimal toBigDecimal(Byte v)
Converts a byte to a big decimal with a scale without. losing precision -- zero scale in this case.


toPlainString

public static final String toPlainString(BigDecimal bd)
Returns a string representation of this BigDecimal without an exponent field. It is the same as BigDecimal.toPlainString() except it works under JDK 1.4.

Since:
5.0.6


Copyright © 2011. All Rights Reserved.