- java.lang.Object
-
- java.lang.Number
-
- java.math.BigDecimal
-
- org.tentackle.common.BMoney
-
- org.tentackle.common.DMoney
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<java.math.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
-
-
Constructor Summary
Constructors Constructor Description DMoney()Creates a zero DMoney with a scale ccording to the currency of the current locale.DMoney(double val, int scale)Creates a DMoney value.DMoney(int scale)Creates a zero DMoney value.DMoney(java.lang.String val, int scale)Creates a DMoney value.DMoney(java.math.BigDecimal val)Creates a DMoney from a BigDecimal (userful for SQL)DMoney(java.math.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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DMoneyabsolute()Gets the absolute value.DMoneyadd(BMoney val)Adds a BMoney to this value and returns a new object.DMoneydivide(double val)Divides a BMoney by double and returns a new object.DMoneyinvert()Inverts this money value.DMoneymultiply(double val)Multiplies this BMoney by a double and returns a new object.DMoneysmallestPositive()Returns the smalles positive value.
Ex.: if scale is 2 --> 0.01 will be returned.DMoneysubtract(BMoney val)Subtracts a BMoney from this value and returns a new object.-
Methods inherited from class org.tentackle.common.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, sqrt, stripTrailingZeros, subtract, subtract, toBigInteger, toBigIntegerExact, toEngineeringString, toPlainString, toString, ulp, unscaledValue, valueOf, valueOf, valueOf
-
-
-
-
Constructor Detail
-
DMoney
public DMoney(double val, int scale)Creates a DMoney value.- Parameters:
val- double-representation of the numberscale- the digits after comma the value should be rounded to
-
DMoney
public DMoney(java.lang.String val, int scale)Creates a DMoney value.- Parameters:
val- the stringscale- 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(java.math.BigInteger intVal, int scale)Creates a DMoney value from a BigInteger.
The scale sets the comma within the given integer.- Parameters:
intVal- the big integerscale- 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 valuescale- the digits after comma the value should be rounded to
-
DMoney
public DMoney(java.math.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:BMoneyAdds a BMoney to this value and returns a new object. This object remains unchanged.
-
subtract
public DMoney subtract(BMoney val)
Description copied from class:BMoneySubtracts a BMoney from this value and returns a new object. This object remains unchanged.
-
multiply
public DMoney multiply(double val)
Description copied from class:BMoneyMultiplies this BMoney by a double and returns a new object. This object remains unchanged.
-
divide
public DMoney divide(double val)
Description copied from class:BMoneyDivides a BMoney by double and returns a new object. This object remains unchanged.
-
smallestPositive
public DMoney smallestPositive()
Description copied from class:BMoneyReturns the smalles positive value.
Ex.: if scale is 2 --> 0.01 will be returned.- Overrides:
smallestPositivein classBMoney- Returns:
- the smalles positive value
-
-