java.lang.Object
java.lang.Number
java.math.BigDecimal
org.tentackle.common.BMoney
org.tentackle.common.DMoney
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<BigDecimal>
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!
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:
-
Field Summary
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, TWO, ZERO -
Constructor Summary
ConstructorsConstructorDescriptionDMoney()Creates a zero DMoney with a scale according to the currency of the current locale.DMoney(double val, int scale) Creates a DMoney value.DMoney(int scale) Creates a zero DMoney value.Creates a DMoney value.DMoney(BigDecimal val) Creates a DMoney from a BigDecimal.DMoney(BigInteger intVal, int scale) Creates a DMoney value from a BigInteger.
The scale sets the comma within the given integer.Creates a DMoney from a BMoney (useful to rescale) -
Method Summary
Modifier and TypeMethodDescriptionabsolute()Gets the absolute value.Adds a BMoney to this value and returns a new object.Gets the decimal value.divide(double val) Divides a BMoney by double and returns a new object.invert()Inverts this money value.multiply(double val) Multiplies this BMoney by a double and returns a new object.Returns the smallest positive value.
Ex.: if scale is 2 --> 0.01 will be returned.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, toWordsMethods 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, valueOfMethods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
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
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
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
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
Creates a DMoney from a BigDecimal.- Parameters:
val- the decimal value
-
DMoney
public DMoney()Creates a zero DMoney with a scale according to the currency of the current locale.
-
-
Method Details
-
bigDecimalValue
Gets the decimal value.- Returns:
- the decimal value
-
add
Description copied from class:BMoneyAdds a BMoney to this value and returns a new object. This object remains unchanged. -
subtract
Description copied from class:BMoneySubtracts a BMoney from this value and returns a new object. This object remains unchanged. -
multiply
Description copied from class:BMoneyMultiplies this BMoney by a double and returns a new object. This object remains unchanged. -
divide
Description copied from class:BMoneyDivides a BMoney by double and returns a new object. This object remains unchanged. -
invert
Description copied from class:BMoneyInverts this money value. -
absolute
Description copied from class:BMoneyGets the absolute value. -
smallestPositive
Description copied from class:BMoneyReturns the smallest positive value.
Ex.: if scale is 2 --> 0.01 will be returned.- Overrides:
smallestPositivein classBMoney- Returns:
- the smallest positive value
-