org.tentackle.util
Class DMoney

java.lang.Object
  extended by java.lang.Number
      extended by java.math.BigDecimal
          extended by org.tentackle.util.BMoney
              extended by org.tentackle.util.DMoney
All Implemented Interfaces:
Serializable, Cloneable, Comparable<BigDecimal>

public class DMoney
extends BMoney

A DMoney is the same as a BMoney but will be treated differently when stored in the database.
A BMoney is stored as a DOUBLE for the value and an INTEGER for the scale. A DMoney is stored as a DECIMAL for the value and an INTEGER for the scale. The DECIMAL is stored with scale 0!

Author:
harald
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.tentackle.util.BMoney
currency
 
Fields inherited from class java.math.BigDecimal
ONE, ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_UNNECESSARY, ROUND_UP, TEN, ZERO
 
Constructor Summary
DMoney()
          Creates a zero DMoney with a scale ccording to the currency of the current locale.
DMoney(BigDecimal val)
          Creates a DMoney from a BigDecimal (userful for SQL)
DMoney(BigInteger intVal, int scale)
          Creates a DMoney value from a BigInteger.
The scale sets the comma within the given integer.
DMoney(BMoney val, int scale)
          Creates a DMoney from a BMoney (useful to rescale)
DMoney(double val, int scale)
          Creates a DMoney value.
DMoney(int scale)
          Creates a zero DMoney value.
DMoney(String val, int scale)
          Creates a DMoney value.
 
Method Summary
 DMoney absolute()
          Gets the absolute value.
 DMoney add(BMoney val)
          Adds a BMoney to this value and returns a new object.
 DMoney divide(double val)
          Divides a BMoney by double and returns a new object.
 DMoney invert()
          Inverts this money value.
 DMoney multiply(double val)
          Multiplies this BMoney by a double and returns a new object.
 DMoney smallestPositive()
          Returns the smalles positive value (i.e.
 DMoney subtract(BMoney val)
          Subtracts a BMoney from this value and returns a new object.
 
Methods inherited from class org.tentackle.util.BMoney
alignScale, clone, divide, isNegative, isPositive, isZero, toWords
 
Methods inherited from class java.math.BigDecimal
abs, abs, add, add, byteValueExact, compareTo, divide, divide, divide, divide, divide, divide, divideAndRemainder, divideAndRemainder, divideToIntegralValue, divideToIntegralValue, doubleValue, equals, floatValue, hashCode, intValue, intValueExact, longValue, longValueExact, max, min, movePointLeft, movePointRight, multiply, multiply, negate, negate, plus, plus, pow, pow, precision, remainder, remainder, round, scale, scaleByPowerOfTen, setScale, setScale, setScale, shortValueExact, signum, stripTrailingZeros, subtract, subtract, toBigInteger, toBigIntegerExact, toEngineeringString, toPlainString, toString, ulp, unscaledValue, valueOf, valueOf, valueOf
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DMoney

public DMoney(double val,
              int scale)
Creates a DMoney value.

Parameters:
val - double-representation of the number
scale - the digits after comma the value should be rounded to

DMoney

public DMoney(String val,
              int scale)
Creates a DMoney value.

Parameters:
val - the string
scale - the digits after comma the value should be rounded to

DMoney

public DMoney(int scale)
Creates a zero DMoney value.

Parameters:
scale - the digits after comma

DMoney

public DMoney(BigInteger intVal,
              int scale)
Creates a DMoney value from a BigInteger.
The scale sets the comma within the given integer.

Parameters:
intVal - the big integer
scale - the digits after comma

DMoney

public DMoney(BMoney val,
              int scale)
Creates a DMoney from a BMoney (useful to rescale)

Parameters:
val - the BMoney or DMoney value
scale - the digits after comma the value should be rounded to

DMoney

public DMoney(BigDecimal val)
Creates a DMoney from a BigDecimal (userful for SQL)

Parameters:
val - the decimal value

DMoney

public DMoney()
Creates a zero DMoney with a scale ccording to the currency of the current locale.

Method Detail

add

public DMoney add(BMoney val)
Description copied from class: BMoney
Adds a BMoney to this value and returns a new object. This object remains unchanged.

Overrides:
add in class BMoney
Parameters:
val - the money value to add
Returns:
the sum of this and given value

subtract

public DMoney subtract(BMoney val)
Description copied from class: BMoney
Subtracts a BMoney from this value and returns a new object. This object remains unchanged.

Overrides:
subtract in class BMoney
Parameters:
val - the money value to subtract
Returns:
this minus the given value

multiply

public DMoney multiply(double val)
Description copied from class: BMoney
Multiplies this BMoney by a double and returns a new object. This object remains unchanged.

Overrides:
multiply in class BMoney
Parameters:
val - the double to multiply with
Returns:
the product of this and given value

divide

public DMoney divide(double val)
Description copied from class: BMoney
Divides a BMoney by double and returns a new object. This object remains unchanged.

Overrides:
divide in class BMoney
Parameters:
val - the value to divide this BMoney by
Returns:
the quotient of this and given value

invert

public DMoney invert()
Description copied from class: BMoney
Inverts this money value.

Overrides:
invert in class BMoney
Returns:
the negated money value

absolute

public DMoney absolute()
Description copied from class: BMoney
Gets the absolute value.

Overrides:
absolute in class BMoney
Returns:
the absolute (positive) value

smallestPositive

public DMoney smallestPositive()
Description copied from class: BMoney
Returns the smalles positive value (i.e. if scale is 2 --> 0.01 will be returned)

Overrides:
smallestPositive in class BMoney
Returns:
the smalles positive value


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de