Class 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
    • 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, ZERO
    • 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
      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.
      Ex.: if scale is 2 --> 0.01 will be returned.
      DMoney subtract​(BMoney val)
      Subtracts a BMoney from this value and returns a new object.
      • 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
      • 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​(java.lang.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​(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 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​(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: 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.
        Ex.: if scale is 2 --> 0.01 will be returned.
        Overrides:
        smallestPositive in class BMoney
        Returns:
        the smalles positive value