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

Variable Index

 o DEFAULT_PRECISION
The default precision is 16 significant digits.

Constructor Index

 o BigDecimalValue(BigDecimal)
Creates a new BigDecimalValue encapsulating the BigDecimal with a default precision.
 o BigDecimalValue(BigDecimal, int)
Creates a new BigDecimalValue encapsulating the BigDecimal with the desired precision.
 o BigDecimalValue(double)
Creates a new BigDecimalValue from a floating point value.
 o BigDecimalValue(double, int)
Creates a new BigDecimalValue from the floating point value with the specified precision.
 o BigDecimalValue(DoubleValue)
Creates a new BigDecimalValue from the floating point value underlying the DoubleValue.
 o BigDecimalValue(DoubleValue, int)
Creates a new BigDecimalValue from the floating point value underlying the DoubleValue with the desired precision.

Method Index

 o abs()
Returns a new value object which has the absolute value of this value.
 o compare(Value)
Compares this value with the specified value.
 o equals(Value)
Returns true if the two values are equal.
 o getPrecision()
Returns the precision
 o getScale()
Returns the scale of this value (the number of the digits to the right of the decimal point).
 o getValue()
Returns the underlying value.
 o greaterThan(Value)
Returns true if this value is greater than the specified value.
 o greaterThanOrEqual(Value)
Returns true if this value is greater than or equal to the specified value.
 o greaterThanZero()
Returns true if this value is greater than zero.
 o isZero()
Returns true if this value is equal to zero.
 o lessThan(Value)
Returns true if this value is less than the specified value.
 o lessThanOrEqual(Value)
Returns true if this value is less than or equal to the specified value.
 o lessThanZero()
Returns true if this value is less than zero.
 o minus(Value)
Returns a value object which has an underlying value equal to the difference between this value and the specified value.
 o negate()
Returns a new value object which has the negation of this value.
 o notEquals(Value)
Returns true if the two values are not equal.
 o over(Value)
Returns a value object which has an underlying value equal to this value divided by the specified value.
 o plus(Value)
Returns a value object which has an underlying value equal to the sum of this value and the specified value.
 o round(int, short, int)
Rounds this value and returns it in a new value object.
 o setPrecision(int)
Sets the precision.
 o setValue(BigDecimal)
Sets the decimal value with no change to the current precision.
 o setValue(BigDecimal, int)
Sets the decimal value and the precision.
 o setValue(double)
Sets the decimal value to the floating-point number.
 o setValue(double, int)
Sets the decimal value to the floating-point number and the specified precision.
 o setValue(DoubleValue)
Sets the decimal value to the underlying floating-point number.
 o setValue(DoubleValue, int)
Sets the decimal value to the underlying floating-point number and the precision.
 o times(Value)
Returns a value object which has an underlying value equal to the product between this value and the specified value.
 o toString()
Returns a string representation of the encapsulated value.

Variables

 o DEFAULT_PRECISION
 public static int DEFAULT_PRECISION
The default precision is 16 significant digits.

Constructors

 o 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
 o 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)
 o 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
 o 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)
 o 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
 o 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)

Methods

 o getValue
 public BigDecimal getValue()
Returns the underlying value.

Returns:
the BigDecimal value.
 o setValue
 public void setValue(BigDecimal value)
Sets the decimal value with no change to the current precision.

Parameters:
value - the desired value
 o 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)
 o 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
 o 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)
 o 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
 o 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)
 o getPrecision
 public int getPrecision()
Returns the precision

Returns:
the current precision
 o setPrecision
 public void setPrecision(int precision)
Sets the precision.

Parameters:
precision - the desired precision (ie. significant digits)
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o abs
 public Value abs()
Returns a new value object which has the absolute value of this value.

Returns:
the absolute value
 o negate
 public Value negate()
Returns a new value object which has the negation of this value.

Returns:
the negation
 o 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
 o 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