Class MonetaryValue

java.lang.Object
rs.baselib.type.MonetaryValue
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MonetaryValue>

public class MonetaryValue
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<MonetaryValue>
A BigDecimal configured for monetary operations.

The BigDecimal is configured with a precision scale of 2, RoundingMode.HALF_UP.

Since:
1.2.9
Author:
ralph
See Also:
Serialized Form
  • Field Details

    • ROUNDING_MODE

      public static final java.math.RoundingMode ROUNDING_MODE
      Banker's rounding
    • MATH_CONTEXT

      public static final java.math.MathContext MATH_CONTEXT
      The MathContext to be used for monetary values
    • DEFAULT_SCALE

      public static final int DEFAULT_SCALE
      The default scale to be used for monetary values
      See Also:
      Constant Field Values
    • ZERO

      public static final MonetaryValue ZERO
      0
  • Constructor Details

    • MonetaryValue

      public MonetaryValue​(java.math.BigDecimal value)
      Constructor.
      Parameters:
      value - the monetary value
    • MonetaryValue

      public MonetaryValue​(MonetaryValue value)
      Constructor.
      Parameters:
      value - the monetary value
    • MonetaryValue

      public MonetaryValue​(java.math.BigDecimal value, java.math.RoundingMode roundingMode)
      Constructor.
      Parameters:
      value - the monetary value
      roundingMode - the rounding mode to be used
    • MonetaryValue

      public MonetaryValue​(java.math.BigDecimal value, java.math.RoundingMode roundingMode, java.math.MathContext mathContext, int scale)
      Constructor.
      Parameters:
      value - the monetary value
      roundingMode - the rounding mode to be used
      mathContext - the MathContext to be used
      scale - the scale to be used
    • MonetaryValue

      public MonetaryValue​(java.lang.CharSequence value)
      Constructor.
      Parameters:
      value - the monetary value
    • MonetaryValue

      public MonetaryValue​(double value)
      Constructor.
      Parameters:
      value - the monetary value
    • MonetaryValue

      public MonetaryValue​(java.math.BigInteger value)
      Constructor.
      Parameters:
      value - the monetary value
    • MonetaryValue

      public MonetaryValue​(int value)
      Constructor.
      Parameters:
      value - the monetary value
    • MonetaryValue

      public MonetaryValue​(long value)
      Constructor.
      Parameters:
      value - the monetary value
  • Method Details

    • getAmount

      public java.math.BigDecimal getAmount()
      Returns the amount.
      Returns:
      the amount
    • setAmount

      public void setAmount​(java.math.BigDecimal amount)
      Sets the amount.
      Parameters:
      amount - the amount to set
    • getRoundingMode

      public java.math.RoundingMode getRoundingMode()
      Returns the rounding mode.
      Returns:
      the rounding mode
    • setRoundingMode

      public void setRoundingMode​(java.math.RoundingMode roundingMode)
      Sets the rounding mode.
      Parameters:
      roundingMode - the rounding mode to set
    • getScale

      public int getScale()
      Returns the scale.
      Returns:
      the scale
    • setScale

      public void setScale​(int scale)
      Sets the scale.
      Parameters:
      scale - the scale to set
    • getMathContext

      public java.math.MathContext getMathContext()
      Returns the MathContext.
      Returns:
      the mathContext
    • setMathContext

      public void setMathContext​(java.math.MathContext mathContext)
      Sets the MathContext.
      Parameters:
      mathContext - the mathContext to set
    • isPositive

      public boolean isPositive()
      Is value positive?
      Returns:
      true when value is a positive number
    • isNegative

      public boolean isNegative()
      Is value negative?
      Returns:
      true when value is a negative number
    • isZero

      public boolean isZero()
      Is value positive?
      Returns:
      true when value is a positive number
    • add

      public MonetaryValue add​(MonetaryValue value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • add

      public MonetaryValue add​(java.math.BigDecimal value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • add

      public MonetaryValue add​(int value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • add

      public MonetaryValue add​(long value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • add

      public MonetaryValue add​(double value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • add

      public MonetaryValue add​(java.math.BigInteger value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • add

      public MonetaryValue add​(java.lang.CharSequence value)
      Adds another value to this object
      Parameters:
      value - value to be added
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(MonetaryValue value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(java.math.BigDecimal value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(int value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(long value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(double value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(java.math.BigInteger value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • subtract

      public MonetaryValue subtract​(java.lang.CharSequence value)
      Subtracts another value from this object.
      Parameters:
      value - value to be subtracted
      Returns:
      new monetary value holding the result
    • multiply

      public MonetaryValue multiply​(java.math.BigDecimal value)
      Multiplies another value with this object.
      Parameters:
      value - value to be multiplied with
      Returns:
      new monetary value holding the result
    • multiply

      public MonetaryValue multiply​(int value)
      Multiplies another value with this object.
      Parameters:
      value - value to be multiplied with
      Returns:
      new monetary value holding the result
    • multiply

      public MonetaryValue multiply​(long value)
      Multiplies another value with this object.
      Parameters:
      value - value to be multiplied with
      Returns:
      new monetary value holding the result
    • multiply

      public MonetaryValue multiply​(double value)
      Multiplies another value with this object.
      Parameters:
      value - value to be multiplied with
      Returns:
      new monetary value holding the result
    • multiply

      public MonetaryValue multiply​(java.math.BigInteger value)
      Multiplies another value with this object.
      Parameters:
      value - value to be multiplied with
      Returns:
      new monetary value holding the result
    • multiply

      public MonetaryValue multiply​(java.lang.CharSequence value)
      Multiplies another value with this object.
      Parameters:
      value - value to be multiplied with
      Returns:
      new monetary value holding the result
    • divide

      public MonetaryValue divide​(java.math.BigDecimal value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      new monetary value holding the result
    • divide

      public MonetaryValue divide​(int value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      new monetary value holding the result
    • divide

      public MonetaryValue divide​(long value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      new monetary value holding the result
    • divide

      public MonetaryValue divide​(double value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      new monetary value holding the result
    • divide

      public MonetaryValue divide​(java.math.BigInteger value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      new monetary value holding the result
    • divide

      public MonetaryValue divide​(java.lang.CharSequence value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      new monetary value holding the result
    • divide

      public java.math.BigDecimal divide​(MonetaryValue value)
      Divides this object by another value.
      Parameters:
      value - value to be divided by
      Returns:
      the result of the operation
    • negate

      public MonetaryValue negate()
      Negates this value.
      Returns:
      new monetary value holding the result
    • getDouble

      public double getDouble()
      Returns this value as a double.
      Returns:
      value as double
      See Also:
      BigDecimal.doubleValue()
    • getFloat

      public float getFloat()
      Returns this value as a float.
      Returns:
      value as float
      See Also:
      BigDecimal.floatValue()
    • getInt

      public int getInt()
      Returns this value as int.
      Returns:
      value as int
      See Also:
      BigDecimal.intValue()
    • getBigInteger

      public java.math.BigInteger getBigInteger()
      Returns this value as BigInteger.
      Returns:
      value as BigInteger
      See Also:
      BigDecimal.toBigInteger()
    • getLong

      public long getLong()
      Returns this value as a long.
      Returns:
      value as long
      See Also:
      BigDecimal.longValue()
    • compareTo

      public int compareTo​(MonetaryValue o)
      Specified by:
      compareTo in interface java.lang.Comparable<MonetaryValue>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object other)
      Overrides:
      equals in class java.lang.Object
    • toString

      public java.lang.String toString()
      The representation of the value as string
      Overrides:
      toString in class java.lang.Object
      Returns:
      e.g. "12.00" or "0.00" or "-2345.34"