All Packages Class Hierarchy This Package Previous Next Index
Class com.roguewave.money.currency.v1_0.BigDecimalValue
java.lang.Object
|
+----com.roguewave.money.currency.v1_0.BigDecimalValue
- public class BigDecimalValue
- extends Object
- implements Value
BigDecimalValue
class encapsulates the JDK's arbitray precision
decimal class, java.math.BigDecimal
. Decimals are exact
representations of decimal fractions. They behave very similarly to floating
point types, float
and double
. However, because
floating-point values use base two, they cannot store decimal fractions
exactly, resulting in rounding errors and a loss of precision. Since
BigDecimal
uses base 10, it can do decimal math exactly.
Why not use BigDecimal
directly? Because,
BigDecimal
has the notion of "scale" which is the number of
digits to the right of the decimal place. We've created the notion of
"precision" in this class. Precision is the total number of digits in the
value. BigDecimalValueValue
provides a way to set a desired
precision. Any operation which violates this precision will cause the error
handler to be invoked.
For the most part, arithmetic between BigDecimalValue
objects is
defined very simply: you get back an exact representation of the result of
the operation. However, if the result cannot be exactly represented as a
BigDecimalValue
because of too many significant digits, the result
is set to an approximation of the true result and the error handler is called
with a PrecisionExceededException.
- Author:
- Trevor Misfeldt
- See Also:
- PrecisionExceededException, ErrorHandler, DefaultErrorHandler, DoubleValue
-
DEFAULT_PRECISION
- The default precision is 16 significant digits.
-
BigDecimalValue(BigDecimal)
- Creates a new BigDecimalValue encapsulating the BigDecimal with a default precision.
-
BigDecimalValue(BigDecimal, int)
- Creates a new BigDecimalValue encapsulating the BigDecimal with the desired precision.
-
BigDecimalValue(double)
- Creates a new BigDecimalValue from a floating point value.
-
BigDecimalValue(double, int)
- Creates a new BigDecimalValue from the floating point value with the
specified precision.
-
BigDecimalValue(DoubleValue)
- Creates a new BigDecimalValue from the floating point value underlying the DoubleValue.
-
BigDecimalValue(DoubleValue, int)
- Creates a new BigDecimalValue from the floating point value underlying the DoubleValue
with the desired precision.
-
abs()
- Returns a new value object which has the absolute value of this value.
-
compare(Value)
- Compares this value with the specified value.
-
equals(Value)
- Returns true if the two values are equal.
-
getPrecision()
- Returns the precision
-
getScale()
- Returns the scale of this value (the number of the digits to the right of the
decimal point).
-
getValue()
- Returns the underlying value.
-
greaterThan(Value)
- Returns true if this value is greater than the specified value.
-
greaterThanOrEqual(Value)
- Returns true if this value is greater than or equal to the specified value.
-
greaterThanZero()
- Returns true if this value is greater than zero.
-
isZero()
- Returns true if this value is equal to zero.
-
lessThan(Value)
- Returns true if this value is less than the specified value.
-
lessThanOrEqual(Value)
- Returns true if this value is less than or equal to the specified value.
-
lessThanZero()
- Returns true if this value is less than zero.
-
minus(Value)
- Returns a value object which has an underlying value equal to the difference
between this value and the specified value.
-
negate()
- Returns a new value object which has the negation of this value.
-
notEquals(Value)
- Returns true if the two values are not equal.
-
over(Value)
- Returns a value object which has an underlying value equal to this value
divided by the specified value.
-
plus(Value)
- Returns a value object which has an underlying value equal to the sum of this
value and the specified value.
-
round(int, short, int)
- Rounds this value and returns it in a new value object.
-
setPrecision(int)
- Sets the precision.
-
setValue(BigDecimal)
- Sets the decimal value with no change to the current precision.
-
setValue(BigDecimal, int)
- Sets the decimal value and the precision.
-
setValue(double)
- Sets the decimal value to the floating-point number.
-
setValue(double, int)
- Sets the decimal value to the floating-point number and the specified
precision.
-
setValue(DoubleValue)
- Sets the decimal value to the underlying floating-point number.
-
setValue(DoubleValue, int)
- Sets the decimal value to the underlying floating-point number and
the precision.
-
times(Value)
- Returns a value object which has an underlying value equal to the product
between this value and the specified value.
-
toString()
- Returns a string representation of the encapsulated value.
DEFAULT_PRECISION
public static int DEFAULT_PRECISION
- The default precision is 16 significant digits.
BigDecimalValue
public BigDecimalValue(BigDecimal value)
- Creates a new BigDecimalValue encapsulating the BigDecimal with a default precision.
- Parameters:
- value - the desired value
- See Also:
- DEFAULT_PRECISION
BigDecimalValue
public BigDecimalValue(BigDecimal value,
int precision)
- Creates a new BigDecimalValue encapsulating the BigDecimal with the desired precision.
- Parameters:
- value - the desired value
- precision - the desired precision (ie. significant digits)
BigDecimalValue
public BigDecimalValue(DoubleValue value)
- Creates a new BigDecimalValue from the floating point value underlying the DoubleValue.
Uses the default precision.
- Parameters:
- value - the desired value
- See Also:
- DEFAULT_PRECISION
BigDecimalValue
public BigDecimalValue(DoubleValue value,
int precision)
- Creates a new BigDecimalValue from the floating point value underlying the DoubleValue
with the desired precision.
- Parameters:
- value - the desired value
- precision - the desired precision (ie. significant digits)
BigDecimalValue
public BigDecimalValue(double value)
- Creates a new BigDecimalValue from a floating point value. Uses the
default precision.
- Parameters:
- value - the desired value
- See Also:
- DEFAULT_PRECISION
BigDecimalValue
public BigDecimalValue(double value,
int precision)
- Creates a new BigDecimalValue from the floating point value with the
specified precision.
- Parameters:
- value - the desired value
- precision - the desired precision (ie. significant digits)
getValue
public BigDecimal getValue()
- Returns the underlying value.
- Returns:
- the BigDecimal value.
setValue
public void setValue(BigDecimal value)
- Sets the decimal value with no change to the current precision.
- Parameters:
- value - the desired value
setValue
public void setValue(BigDecimal value,
int precision)
- Sets the decimal value and the precision.
- Parameters:
- value - the desired value
- precision - the desired precision (ie. significant digits)
setValue
public void setValue(DoubleValue value)
- Sets the decimal value to the underlying floating-point number. There
is no change to the precision.
- Parameters:
- value - the desired value
setValue
public void setValue(DoubleValue value,
int precision)
- Sets the decimal value to the underlying floating-point number and
the precision.
- Parameters:
- value - the desired value
- precision - the desired precision (ie. significant digits)
setValue
public void setValue(double value)
- Sets the decimal value to the floating-point number. There is no
change to the precision.
- Parameters:
- value - the desired value
setValue
public void setValue(double value,
int precision)
- Sets the decimal value to the floating-point number and the specified
precision.
- Parameters:
- value - the desired value
- precision - the desired precision (ie. significant digits)
getPrecision
public int getPrecision()
- Returns the precision
- Returns:
- the current precision
setPrecision
public void setPrecision(int precision)
- Sets the precision.
- Parameters:
- precision - the desired precision (ie. significant digits)
getScale
public int getScale()
- Returns the scale of this value (the number of the digits to the right of the
decimal point).
- Returns:
- the current scale
plus
public Value plus(Value value)
- Returns a value object which has an underlying value equal to the sum of this
value and the specified value. The precision is equal to the minimum of the
two precisions.
- Parameters:
- value - the operand
- Returns:
- the sum
minus
public Value minus(Value value)
- Returns a value object which has an underlying value equal to the difference
between this value and the specified value. The precision is equal to the
minimum of the two precisions.
- Parameters:
- value - the operand
- Returns:
- the difference
times
public Value times(Value value)
- Returns a value object which has an underlying value equal to the product
between this value and the specified value. The precision is equal to the
minimum of the two precisions.
- Parameters:
- value - the operand
- Returns:
- the product
over
public Value over(Value value)
- Returns a value object which has an underlying value equal to this value
divided by the specified value. The precision is equal to the minimum
of the two precisions.
- Parameters:
- value - the divisor
- Returns:
- the quotient
equals
public boolean equals(Value value)
- Returns true if the two values are equal. False, otherwise. Precisions
are ignored.
- Parameters:
- value - the value for comparison
- Returns:
- whether the two values are equal or not
notEquals
public boolean notEquals(Value value)
- Returns true if the two values are not equal. False, otherwise.
Precisions are ignored.
- Parameters:
- value - the value for comparison
- Returns:
- whether the two values are not equal
lessThan
public boolean lessThan(Value value)
- Returns true if this value is less than the specified value. False, otherwise.
Precisions are ignored.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is less than the specified value
greaterThan
public boolean greaterThan(Value value)
- Returns true if this value is greater than the specified value. False,
otherwise. Precisions are ignored.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is greater than the specified value
lessThanOrEqual
public boolean lessThanOrEqual(Value value)
- Returns true if this value is less than or equal to the specified value.
False, otherwise. Precisions are ignored.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is less than or equal to the specified value
greaterThanOrEqual
public boolean greaterThanOrEqual(Value value)
- Returns true if this value is greater than or equal to the specified value.
False, otherwise. Precisions are ignored.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is greater than or equal to the specified value
compare
public int compare(Value value)
- Compares this value with the specified value. Precisions are ignored.
- Parameters:
- the - value to compare
- Returns:
- -1 if this value is less than the specified value, 0 if they are equal,
or 1 if this value is greater
isZero
public boolean isZero()
- Returns true if this value is equal to zero. False, otherwise.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is zero
lessThanZero
public boolean lessThanZero()
- Returns true if this value is less than zero. False, otherwise.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is less than zero
greaterThanZero
public boolean greaterThanZero()
- Returns true if this value is greater than zero. False, otherwise.
- Parameters:
- value - the value for comparison
- Returns:
- whether this value is greater than zero
abs
public Value abs()
- Returns a new value object which has the absolute value of this value.
- Returns:
- the absolute value
negate
public Value negate()
- Returns a new value object which has the negation of this value.
- Returns:
- the negation
round
public Value round(int accuracy,
short rounding,
int digit)
- Rounds this value and returns it in a new value object.
- Parameters:
- accuracy - The desired digits after the decimal point.
- rounding - the desired rounding method
- digit - the desired digit to round on. For example, '
5
'.
- Returns:
- the rounded value
- See Also:
- NO_ROUND, ROUND_UP, ROUND_DOWN, ROUND_PLAIN, ROUND_BANKERS
toString
public String toString()
- Returns a string representation of the encapsulated value.
- Returns:
- the value as a string
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index