Module java.money
Package javax.money

Interface MonetaryAmount

All Superinterfaces:
java.lang.Comparable<MonetaryAmount>, CurrencySupplier, NumberSupplier

public interface MonetaryAmount
extends CurrencySupplier, NumberSupplier, java.lang.Comparable<MonetaryAmount>
Interface defining a monetary amount. The effective format representation of an amount may vary depending on the implementation used. JSR 354 explicitly supports different types of monetary amounts to be implemented and used. Reason behind is that the requirements to an implementation heavily vary for different usage scenarios. E.g. product calculations may require high precision and scale, whereas low latency order and trading systems require high calculation performance for algorithmic operations.

Each instance of an amount provides additional meta-data in form of a MonetaryContext. This context contains detailed information on the numeric capabilities, e.g. the supported precision and maximal scale, as well as the common implementation flavor. Also a MonetaryAmount provides a NumberValue, which allows easily to extract the numeric value, of the amount. And finally getFactory() provides a MonetaryAmountFactory, which allows to of instances of MonetaryAmount based on the same numeric implementation.

This JSR additionally recommends to consider the following aspects:

  • Arithmetic operations should throw an ArithmeticException, if performing arithmetic operations between amounts exceeds the capabilities of the numeric representation type used. Any implicit truncating, that would lead to complete invalid and useless results, should be avoided. This recommendation does not affect format rounding, as required by the format numeric representation of a monetary amount.
  • Monetary amounts should allow numbers as argument for arithmetic operations like division and multiplication. Adding or subtracting of amounts must only be possible by passing instances of MonetaryAmount.
  • Nevertheless numeric truncation is also explicitly supported when calling NumberValue.numberValue(Class), whereas the exact counterpart, NumberValue.numberValueExact(Class), works similar to BigDecimal.longValueExact().
  • Since implementations are recommended to be immutable, an operation should never change any format state of an instance. Given an instance, all operations are required to be fully reproducible.
  • Finally the result of calling with(MonetaryOperator) must be of the same type as type on which with was called. The with method also defines additional interoperability requirements that are important to enable this invariant.
  • To enable further interoperability a static method from(MonetaryAmount) is recommended to be implemented on each implementation class, that allows conversion of a MonetaryAmount to a concrete instance. E.g.a class MyMoney extends MonetaryAmount would contain the following method:
    
     public final class MyMoney implements MonetaryAmount{
       ...
       public static MyMoney from(MonetaryAmount amount)(...)
     }
     

Implementation specification

Implementations of this interface must be
  • thread-safe
Implementations of this interface should be Implementations of this interface must be
  • thread-safe
  • immutable
  • comparable
  • must implement equals/hashCode, hereby considering
    • Implementation type
    • CurrencyUnit
    • Numeric value.
    This also means that two different implementations types with the same currency and numeric value are NOT equal.

Version:
1.1
Author:
Anatole Tresch, Werner Keil
See Also:
with(MonetaryOperator)
  • Method Summary

    Modifier and Type Method Description
    MonetaryAmount abs()
    Returns a MonetaryAmount whose value is the absolute value of this MonetaryAmount, and whose scale is this.getContext().getMaxScale().
    MonetaryAmount add​(MonetaryAmount augend)
    Returns a MonetaryAmount whose value is this + augend, and whose scale is max(this.getContext().getMaxScale(), augend.getContext().getMaxScale()).
    MonetaryAmount divide​(double divisor)
    Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.
    MonetaryAmount divide​(long divisor)
    Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.
    MonetaryAmount divide​(java.lang.Number divisor)
    Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.
    MonetaryAmount[] divideAndRemainder​(double divisor)
    Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.
    MonetaryAmount[] divideAndRemainder​(long divisor)
    Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.
    MonetaryAmount[] divideAndRemainder​(java.lang.Number divisor)
    Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.
    MonetaryAmount divideToIntegralValue​(double divisor)
    Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.
    MonetaryAmount divideToIntegralValue​(long divisor)
    Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.
    MonetaryAmount divideToIntegralValue​(java.lang.Number divisor)
    Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.
    MonetaryContext getContext()
    Returns the MonetaryContext of this MonetaryAmount.
    MonetaryAmountFactory<? extends MonetaryAmount> getFactory()
    Creates a new MonetaryAmountFactory, returning the same implementation type Hereby this given amount is used as a template, so reusing the CurrencyUnit, its numeric value, the algorithmic implementation as well as the current MonetaryContext.
    boolean isEqualTo​(MonetaryAmount amount)
    Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
    boolean isGreaterThan​(MonetaryAmount amount)
    Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
    boolean isGreaterThanOrEqualTo​(MonetaryAmount amount)
    Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
    boolean isLessThan​(MonetaryAmount amount)
    Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
    boolean isLessThanOrEqualTo​(MonetaryAmount amt)
    Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
    default boolean isNegative()
    Checks if a MonetaryAmount is negative.
    default boolean isNegativeOrZero()
    Checks if a MonetaryAmount is negative or zero.
    default boolean isPositive()
    Checks if a MonetaryAmount is positive.
    default boolean isPositiveOrZero()
    Checks if a MonetaryAmount is positive or zero.
    default boolean isZero()
    Checks if an MonetaryAmount is zero.
    MonetaryAmount multiply​(double multiplicand)
    Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().
    MonetaryAmount multiply​(long multiplicand)
    Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().
    MonetaryAmount multiply​(java.lang.Number multiplicand)
    Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().
    MonetaryAmount negate()
    Returns a MonetaryAmount whose value is -this, and whose scale is this.getContext().getMaxScale(), with rounding according to the context settings.
    MonetaryAmount plus()
    Returns a MonetaryAmount whose value is +this.
    default <R> R query​(MonetaryQuery<R> query)
    Queries this monetary amount for a value.
    MonetaryAmount remainder​(double divisor)
    Returns a MonetaryAmount whose value is this % divisor.
    MonetaryAmount remainder​(long divisor)
    Returns a MonetaryAmount whose value is this % divisor.
    MonetaryAmount remainder​(java.lang.Number divisor)
    Returns a MonetaryAmount whose value is this % divisor.
    MonetaryAmount scaleByPowerOfTen​(int power)
    Returns a MonetaryAmount whose numerical value is equal to ( this * 10n).
    int signum()
    Returns the signum function of this MonetaryAmount.
    MonetaryAmount stripTrailingZeros()
    Returns a MonetaryAmount which is numerically equal to this one but with any trailing zeros removed from the representation.
    MonetaryAmount subtract​(MonetaryAmount subtrahend)
    Returns a MonetaryAmount whose value is this - amount, and whose scale is max(this.getContext().getMaxScale(), subtrahend.getContext().getMaxScale().
    default MonetaryAmount with​(MonetaryOperator operator)
    Returns an operated object of the same type as this object with the operation made.

    Methods inherited from interface java.lang.Comparable

    compareTo

    Methods inherited from interface javax.money.CurrencySupplier

    getCurrency

    Methods inherited from interface javax.money.NumberSupplier

    getNumber
  • Method Details

    • getContext

      MonetaryContext getContext()
      Returns the MonetaryContext of this MonetaryAmount. The MonetaryContext provides additional information about the numeric representation and the numeric capabilities. This information can be used by code to determine situations where MonetaryAmount instances must be converted to avoid implicit truncation, which can lead to invalid results.
      Returns:
      the MonetaryContext of this MonetaryAmount, never null .
    • query

      default <R> R query​(MonetaryQuery<R> query)
      Queries this monetary amount for a value.

      This queries this amount using the specified query strategy object.

      Implementations must ensure that no observable state is altered when this read-only method is invoked.

      Type Parameters:
      R - the type of the result
      Parameters:
      query - the query to invoke, not null
      Returns:
      the query result, null may be returned (defined by the query)
    • with

      default MonetaryAmount with​(MonetaryOperator operator)
      Returns an operated object of the same type as this object with the operation made. Hereby returning an instance of the same type is very important to prevent uncontrolled mixup of implementations. Switching between implementations is still easily possible, e.g. by using according MonetaryAmountFactory instances:
      
       // converting from Money to MyMoney
       Money m = ...;
       MonetartyAmountFactory<MyMoney> f = Monetary.queryAmountFactory(MyMoney.class);
       MyMoney myMoney = f.setAmount(m).of();
       

      This converts this monetary amount according to the rules of the specified operator. A typical operator will change the amount and leave the currency unchanged. A more complex operator might also change the currency.

      Some example code indicating how and why this method is used:

      
       MonetaryAmount money = money.with(amountMultipliedBy(2));
       money = money.with(amountRoundedToNearestWholeUnit());
       

      Hereby also the method signature on the implementation type must return the concrete type, to enable a fluent API, e.g.

      
       public final class MyMoney implements MonetaryAmount{
         ...
         public MyMoney with(MonetaryOperator operator){
           ...
         }
      
         ...
       }
       
      Parameters:
      operator - the operator to use, not null
      Returns:
      an object of the same type with the specified conversion made, not null
    • getFactory

      MonetaryAmountFactory<? extends MonetaryAmount> getFactory()
      Creates a new MonetaryAmountFactory, returning the same implementation type Hereby this given amount is used as a template, so reusing the CurrencyUnit, its numeric value, the algorithmic implementation as well as the current MonetaryContext.

      This method is used for creating a new amount result after having done calculations that are not directly mappable to the default monetary arithmetics, e.g. currency conversion.

      Returns:
      the new MonetaryAmountFactory with the given MonetaryAmount as its default values.
    • isGreaterThan

      boolean isGreaterThan​(MonetaryAmount amount)
      Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      Parameters:
      amount - the MonetaryAmount to be compared with this instance.
      Returns:
      true if amount > this.
      Throws:
      MonetaryException - if the amount's currency is not equal to the currency of this instance.
    • isGreaterThanOrEqualTo

      boolean isGreaterThanOrEqualTo​(MonetaryAmount amount)
      Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      Parameters:
      amount - the MonetaryAmount to be compared with this instance.
      Returns:
      true if amount >= this.
      Throws:
      MonetaryException - if the amount's currency is not equal to the currency of this instance.
    • isLessThan

      boolean isLessThan​(MonetaryAmount amount)
      Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      Parameters:
      amount - the MonetaryAmount to be compared with this instance.
      Returns:
      true if amount < this.
      Throws:
      MonetaryException - if the amount's currency is not equal to the currency of this instance.
    • isLessThanOrEqualTo

      boolean isLessThanOrEqualTo​(MonetaryAmount amt)
      Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      Parameters:
      amt - the MonetaryAmount to be compared with this instance.
      Returns:
      true if amount <= this.
      Throws:
      MonetaryException - if the amount's currency is not equal to the currency of this instance.
    • isEqualTo

      boolean isEqualTo​(MonetaryAmount amount)
      Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      Parameters:
      amount - the MonetaryAmount to be compared with this instance.
      Returns:
      true if amount == this.
      Throws:
      MonetaryException - if the amount's currency is not equal to the currency of this instance.
    • isNegative

      default boolean isNegative()
      Checks if a MonetaryAmount is negative.
      Returns:
      true if signum() < 0.
    • isNegativeOrZero

      default boolean isNegativeOrZero()
      Checks if a MonetaryAmount is negative or zero.
      Returns:
      true if signum() <= 0.
    • isPositive

      default boolean isPositive()
      Checks if a MonetaryAmount is positive.
      Returns:
      true if signum() > 0.
    • isPositiveOrZero

      default boolean isPositiveOrZero()
      Checks if a MonetaryAmount is positive or zero.
      Returns:
      true if signum() >= 0.
    • isZero

      default boolean isZero()
      Checks if an MonetaryAmount is zero.
      Returns:
      true if signum() == 0.
    • signum

      int signum()
      Returns the signum function of this MonetaryAmount.
      Returns:
      -1, 0, or 1 as the value of this MonetaryAmount is negative, zero, or positive.
    • add

      Returns a MonetaryAmount whose value is this + augend, and whose scale is max(this.getContext().getMaxScale(), augend.getContext().getMaxScale()).
      Parameters:
      augend - value to be added to this MonetaryAmount.
      Returns:
      this + augend
      Throws:
      java.lang.ArithmeticException - if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • subtract

      MonetaryAmount subtract​(MonetaryAmount subtrahend)
      Returns a MonetaryAmount whose value is this - amount, and whose scale is max(this.getContext().getMaxScale(), subtrahend.getContext().getMaxScale().
      Parameters:
      subtrahend - value to be subtracted from this MonetaryAmount.
      Returns:
      this - subtrahend
      Throws:
      java.lang.ArithmeticException - if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • multiply

      MonetaryAmount multiply​(long multiplicand)
      Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().
      Parameters:
      multiplicand - value to be multiplied by this MonetaryAmount.
      Returns:
      this * multiplicand
      Throws:
      java.lang.ArithmeticException - if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • multiply

      MonetaryAmount multiply​(double multiplicand)
      Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale(). By default the input value's scale will be rounded to accommodate the format capabilities, and no ArithmeticException is thrown if the input number's scale exceeds the capabilities.
      Parameters:
      multiplicand - value to be multiplied by this MonetaryAmount. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.
      Returns:
      this * multiplicand
      Throws:
      java.lang.ArithmeticException - if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • multiply

      MonetaryAmount multiply​(java.lang.Number multiplicand)
      Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().
      Parameters:
      multiplicand - value to be multiplied by this MonetaryAmount. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.
      Returns:
      this * multiplicand
      Throws:
      java.lang.ArithmeticException - if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • divide

      MonetaryAmount divide​(long divisor)
      Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.
      Parameters:
      divisor - value by which this MonetaryAmount is to be divided.
      Returns:
      this / divisor
      Throws:
      java.lang.ArithmeticException - if the exact quotient does not have a terminating decimal expansion, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • divide

      MonetaryAmount divide​(double divisor)
      Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.
      Parameters:
      divisor - value by which this MonetaryAmount is to be divided.
      Returns:
      this / divisor
      Throws:
      java.lang.ArithmeticException - if the exact quotient does not have a terminating decimal expansion, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • divide

      MonetaryAmount divide​(java.lang.Number divisor)
      Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.
      Parameters:
      divisor - value by which this MonetaryAmount is to be divided.
      Returns:
      this / divisor
      Throws:
      java.lang.ArithmeticException - if the exact quotient does not have a terminating decimal expansion, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • remainder

      MonetaryAmount remainder​(long divisor)
      Returns a MonetaryAmount whose value is this % divisor.

      The remainder is given by this.subtract(this.divideToIntegralValue(divisor).multiply(divisor) . Note that this is not the modulo operation (the result can be negative).

      Parameters:
      divisor - value by which this MonetaryAmount is to be divided.
      Returns:
      this % divisor.
      Throws:
      java.lang.ArithmeticException - if divisor==0, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • remainder

      MonetaryAmount remainder​(double divisor)
      Returns a MonetaryAmount whose value is this % divisor.

      The remainder is given by this.subtract(this.divideToIntegralValue(divisor).multiply(divisor) . Note that this is not the modulo operation (the result can be negative).

      Parameters:
      divisor - value by which this MonetaryAmount is to be divided.
      Returns:
      this % divisor.
      Throws:
      java.lang.ArithmeticException - if divisor==0, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • remainder

      MonetaryAmount remainder​(java.lang.Number divisor)
      Returns a MonetaryAmount whose value is this % divisor.

      The remainder is given by this.subtract(this.divideToIntegralValue(divisor).multiply(divisor) . Note that this is not the modulo operation (the result can be negative).

      Parameters:
      divisor - value by which this MonetaryAmount is to be divided.
      Returns:
      this % divisor.
      Throws:
      java.lang.ArithmeticException - if divisor==0, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • divideAndRemainder

      MonetaryAmount[] divideAndRemainder​(long divisor)
      Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

      Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

      Parameters:
      divisor - value by which this MonetaryAmount is to be divided, and the remainder computed.
      Returns:
      a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
      Throws:
      java.lang.ArithmeticException - if divisor==0, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
      See Also:
      divideToIntegralValue(long), remainder(long)
    • divideAndRemainder

      MonetaryAmount[] divideAndRemainder​(double divisor)
      Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

      Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

      Parameters:
      divisor - value by which this MonetaryAmount is to be divided, and the remainder computed.
      Returns:
      a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
      Throws:
      java.lang.ArithmeticException - if divisor==0, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
      See Also:
      divideToIntegralValue(double), remainder(double)
    • divideAndRemainder

      MonetaryAmount[] divideAndRemainder​(java.lang.Number divisor)
      Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

      Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

      Parameters:
      divisor - value by which this MonetaryAmount is to be divided, and the remainder computed.
      Returns:
      a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
      Throws:
      java.lang.ArithmeticException - if divisor==0, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
      See Also:
      divideToIntegralValue(Number), remainder(Number)
    • divideToIntegralValue

      MonetaryAmount divideToIntegralValue​(long divisor)
      Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down. The preferred scale of the result is this.getContext().getMaxScale() - divisor.getContext().getMaxScale().
      Parameters:
      divisor - value by which this BigDecimal is to be divided.
      Returns:
      The integer part of this / divisor.
      Throws:
      java.lang.ArithmeticException - if divisor==0
      See Also:
      BigDecimal.divideToIntegralValue(java.math.BigDecimal)
    • divideToIntegralValue

      MonetaryAmount divideToIntegralValue​(double divisor)
      Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down. The preferred scale of the result is this.getContext().getMaxScale() - divisor.getContext().getMaxScale().
      Parameters:
      divisor - value by which this BigDecimal is to be divided.
      Returns:
      The integer part of this / divisor.
      Throws:
      java.lang.ArithmeticException - if divisor==0
      See Also:
      BigDecimal.divideToIntegralValue(java.math.BigDecimal)
    • divideToIntegralValue

      MonetaryAmount divideToIntegralValue​(java.lang.Number divisor)
      Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down. The preferred scale of the result is this.getContext().getMaxScale() - divisor.getContext().getMaxScale().
      Parameters:
      divisor - value by which this BigDecimal is to be divided.
      Returns:
      The integer part of this / divisor.
      Throws:
      java.lang.ArithmeticException - if divisor==0
      See Also:
      BigDecimal.divideToIntegralValue(java.math.BigDecimal)
    • scaleByPowerOfTen

      MonetaryAmount scaleByPowerOfTen​(int power)
      Returns a MonetaryAmount whose numerical value is equal to ( this * 10n). The scale of the result is this.getContext().getMaxScale() - n.
      Parameters:
      power - the power.
      Returns:
      the calculated amount value.
      Throws:
      java.lang.ArithmeticException - if the scale would be outside the range of a 32-bit integer, or if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
    • abs

      Returns a MonetaryAmount whose value is the absolute value of this MonetaryAmount, and whose scale is this.getContext().getMaxScale().
      Returns:
      abs(this
    • negate

      MonetaryAmount negate()
      Returns a MonetaryAmount whose value is -this, and whose scale is this.getContext().getMaxScale(), with rounding according to the context settings.
      Returns:
      -this, rounded as necessary.
      Throws:
      java.lang.ArithmeticException - if rounding fails.
      See Also:
      BigDecimal.negate()
    • plus

      Returns a MonetaryAmount whose value is +this.

      This method, which simply returns this MonetaryAmount is included for symmetry with the unary minus method negate().

      Returns:
      this.
      See Also:
      negate(), BigDecimal.plus()
    • stripTrailingZeros

      MonetaryAmount stripTrailingZeros()
      Returns a MonetaryAmount which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the MonetaryAmount value CHF 600.0, which has [BigInteger, scale] components equals to [6000, 1], yields 6E2 with [ BigInteger, scale] components equals to [6, -2]
      Returns:
      a numerically equal MonetaryAmount with any trailing zeros removed.