Package org.zkoss.math
Class BigDecimals
java.lang.Object
org.zkoss.math.BigDecimals
Utilities and constants of big decimals.
- Author:
- tomyeh
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRepresents our fine number precision.static final intRepresents our fine number scale.static final BigDecimalRepresents -1 in big decimal.static final intRepresents our number precision.static final intRepresents our number scale.static final BigDecimalRepresents 1 in big decimal.static final BigDecimalRepresents 0 in big decimal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final BigDecimaltoBigDecimal(byte v) Converts a byte to a big decimal with a scale without.static final BigDecimaltoBigDecimal(double v, int scale) Converts a double to a big decimal with a scale.static final BigDecimaltoBigDecimal(double v, int scale, int roundingMode) Converts a double to a big decimal with a scale.static final BigDecimaltoBigDecimal(int v) Converts an integer to a big decimal with a scale without.static final BigDecimaltoBigDecimal(int v, int scale) Converts an integer to a big decimal with a scale.static final BigDecimaltoBigDecimal(long v) Converts a long to a big decimal with a scale without.static final BigDecimaltoBigDecimal(long v, int scale) Converts an integer to a big decimal with a scale.static final BigDecimaltoBigDecimal(short v) Converts a short to a big decimal with a scale without.static final BigDecimaltoBigDecimal(Byte v) Converts a byte to a big decimal with a scale without.static final BigDecimalConverts an integer to a big decimal with a scale without.static final BigDecimaltoBigDecimal(Long v) Converts a long to a big decimal with a scale without.static final BigDecimalConverts a short to a big decimal with a scale without.static final StringtoLocaleString(BigDecimal bd, Locale locale) Return a string representation of this BigDecimal without an exponent field, which respects the given locale.
-
Field Details
-
ZERO
Represents 0 in big decimal. -
ONE
Represents 1 in big decimal. -
MINUS_ONE
Represents -1 in big decimal. -
NUMBER_PRECISION
public static final int NUMBER_PRECISIONRepresents our number precision.- See Also:
-
NUMBER_SCALE
public static final int NUMBER_SCALERepresents our number scale.- See Also:
-
FINE_NUMBER_PRECISION
public static final int FINE_NUMBER_PRECISIONRepresents our fine number precision.- See Also:
-
FINE_NUMBER_SCALE
public static final int FINE_NUMBER_SCALERepresents our fine number scale.- See Also:
-
-
Constructor Details
-
BigDecimals
public BigDecimals()
-
-
Method Details
-
toBigDecimal
Converts a double to a big decimal with a scale.It is strongly deprecated to use new Decimal(double) since the scale is unpredictable and usually surprising. For example, BigDecimal(.1) will becomes .1000000000000000055511151231257827021181583404541015625. On the other hand, BigDecimal("0.1") will be 0.1 correctly.
- Parameters:
scale- the BigDecimal's scaleroundingMode- the rounding mode
-
toBigDecimal
Converts a double to a big decimal with a scale. It usesBigDecimal.ROUND_HALF_UP. -
toBigDecimal
Converts an integer to a big decimal with a scale. -
toBigDecimal
Converts an integer to a big decimal with a scale. -
toBigDecimal
Converts an integer to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts a long to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts a short to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts a byte to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts an integer to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts a long to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts a short to a big decimal with a scale without. losing precision -- zero scale in this case. -
toBigDecimal
Converts a byte to a big decimal with a scale without. losing precision -- zero scale in this case. -
toLocaleString
Return a string representation of this BigDecimal without an exponent field, which respects the given locale.- Parameters:
locale- if null, the current user locale is used.- Since:
- 5.0.10
-