Top Description Methods
javax.money

public Interface MonetaryAmount

extends CurrencySupplier, NumberSupplier, 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:

Implementation specification

Implementations of this interface must be Implementations of this interface should be Implementations of this interface must be

Authors
Anatole Tresch, Werner Keil
Version
1.1
See Also
with(MonetaryOperator)

Method Summary

Modifier and TypeMethod and Description
public MonetaryAmount

Returns:

abs(this
abs
()

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

public MonetaryAmount

Returns:

this + augend
add
(MonetaryAmount
value to be added to this MonetaryAmount.
augend
)

Returns a MonetaryAmount whose value is this + augend, and whose scale is max(this.getContext().getMaxScale(), augend.getContext().getMaxScale()).

public MonetaryAmount

Returns:

this / divisor
divide
(long
value by which this MonetaryAmount is to be divided.
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.

public MonetaryAmount

Returns:

this / divisor
divide
(double
value by which this MonetaryAmount is to be divided.
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.

public MonetaryAmount

Returns:

this / divisor
divide
(Number
value by which this MonetaryAmount is to be divided.
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.

public MonetaryAmount[]

Returns:

a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
divideAndRemainder
(long
value by which this MonetaryAmount is to be divided, and the remainder computed.
divisor
)

Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

public MonetaryAmount[]

Returns:

a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
divideAndRemainder
(double
value by which this MonetaryAmount is to be divided, and the remainder computed.
divisor
)

Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

public MonetaryAmount[]

Returns:

a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
divideAndRemainder
(Number
value by which this MonetaryAmount is to be divided, and the remainder computed.
divisor
)

Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

public MonetaryAmount

Returns:

The integer part of this / divisor.
divideToIntegralValue
(long
value by which this BigDecimal is to be divided.
divisor
)

Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.

public MonetaryAmount

Returns:

The integer part of this / divisor.
divideToIntegralValue
(double
value by which this BigDecimal is to be divided.
divisor
)

Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.

public MonetaryAmount

Returns:

The integer part of this / divisor.
divideToIntegralValue
(Number
value by which this BigDecimal is to be divided.
divisor
)

Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.

public MonetaryContext

Returns:

the MonetaryContext of this MonetaryAmount, never null .
getContext
()

Returns the MonetaryContext of this MonetaryAmount.

public MonetaryAmountFactory<? extends MonetaryAmount>

Returns:

the new MonetaryAmountFactory with the given MonetaryAmount as its default values.
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.

public boolean

Returns:

true if amount == this.
isEqualTo
(MonetaryAmount
the MonetaryAmount to be compared with this instance.
amount
)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean

Returns:

true if amount > this.
isGreaterThan
(MonetaryAmount
the MonetaryAmount to be compared with this instance.
amount
)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean

Returns:

true if amount >= this.
isGreaterThanOrEqualTo
(MonetaryAmount
the MonetaryAmount to be compared with this instance.
amount
)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean

Returns:

true if amount < this.
isLessThan
(MonetaryAmount
the MonetaryAmount to be compared with this instance.
amount
)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean

Returns:

true if amount <= this.
isLessThanOrEqualTo
(MonetaryAmount
the MonetaryAmount to be compared with this instance.
amt
)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public default boolean

Returns:

true if signum() < 0.
isNegative
()

Checks if a MonetaryAmount is negative.

public default boolean

Returns:

true if signum() <= 0.
isNegativeOrZero
()

Checks if a MonetaryAmount is negative or zero.

public default boolean

Returns:

true if signum() > 0.
isPositive
()

Checks if a MonetaryAmount is positive.

public default boolean

Returns:

true if signum() >= 0.
isPositiveOrZero
()

Checks if a MonetaryAmount is positive or zero.

public default boolean

Returns:

true if signum() == 0.
isZero
()

Checks if an MonetaryAmount is zero.

public MonetaryAmount

Returns:

this * multiplicand
multiply
(long
value to be multiplied by this MonetaryAmount.
multiplicand
)

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

public MonetaryAmount

Returns:

this * multiplicand
multiply
(double
value to be multiplied by this MonetaryAmount. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.
multiplicand
)

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

public MonetaryAmount

Returns:

this * multiplicand
multiply
(Number
value to be multiplied by this MonetaryAmount. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.
multiplicand
)

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

public MonetaryAmount

Returns:

-this, rounded as necessary.
negate
()

Returns a MonetaryAmount whose value is -this, and whose scale is this.getContext().getMaxScale(), with rounding according to the context settings.

public MonetaryAmount

Returns:

this.
plus
()

Returns a MonetaryAmount whose value is +this.

public default <
the type of the result
R
>
R

Returns:

the query result, null may be returned (defined by the query)
query
(MonetaryQuery<R>
the query to invoke, not null
query
)

Queries this monetary amount for a value.

public MonetaryAmount

Returns:

this % divisor.
remainder
(long
value by which this MonetaryAmount is to be divided.
divisor
)

Returns a MonetaryAmount whose value is this % divisor.

public MonetaryAmount

Returns:

this % divisor.
remainder
(double
value by which this MonetaryAmount is to be divided.
divisor
)

Returns a MonetaryAmount whose value is this % divisor.

public MonetaryAmount

Returns:

this % divisor.
remainder
(Number
value by which this MonetaryAmount is to be divided.
divisor
)

Returns a MonetaryAmount whose value is this % divisor.

public MonetaryAmount

Returns:

the calculated amount value.
scaleByPowerOfTen
(int
the power.
power
)

Returns a MonetaryAmount whose numerical value is equal to ( this * 10n).

public int

Returns:

-1, 0, or 1 as the value of this MonetaryAmount is negative, zero, or positive.
signum
()

Returns the signum function of this MonetaryAmount.

public MonetaryAmount

Returns:

a numerically equal MonetaryAmount with any trailing zeros removed.
stripTrailingZeros
()

Returns a MonetaryAmount which is numerically equal to this one but with any trailing zeros removed from the representation.

public MonetaryAmount

Returns:

this - subtrahend
subtract
(MonetaryAmount
value to be subtracted from this MonetaryAmount.
subtrahend
)

Returns a MonetaryAmount whose value is this - amount, and whose scale is max(this.getContext().getMaxScale(), subtrahend.getContext().getMaxScale().

public default MonetaryAmount

Returns:

an object of the same type with the specified conversion made, not null
with
(MonetaryOperator
the operator to use, not null
operator
)

Returns an operated object of the same type as this object with the operation made.

Inherited from java.lang.Comparable:
compareTo
Inherited from javax.money.CurrencySupplier:
getCurrency
Inherited from javax.money.NumberSupplier:
getNumber

Method Detail

absback to summary
public MonetaryAmount abs()

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

Returns:MonetaryAmount

abs(this

addback to summary
public MonetaryAmount add(MonetaryAmount augend)

Returns a MonetaryAmount whose value is this + augend, and whose scale is max(this.getContext().getMaxScale(), augend.getContext().getMaxScale()).

Parameters
augend:MonetaryAmount

value to be added to this MonetaryAmount.

Returns:MonetaryAmount

this + augend

Exceptions
ArithmeticException:
if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
divideback to summary
public 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:long

value by which this MonetaryAmount is to be divided.

Returns:MonetaryAmount

this / divisor

Exceptions
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.
divideback to summary
public 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:double

value by which this MonetaryAmount is to be divided.

Returns:MonetaryAmount

this / divisor

Exceptions
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.
divideback to summary
public MonetaryAmount divide(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:Number

value by which this MonetaryAmount is to be divided.

Returns:MonetaryAmount

this / divisor

Exceptions
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.
divideAndRemainderback to summary
public 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:long

value by which this MonetaryAmount is to be divided, and the remainder computed.

Returns:MonetaryAmount[]

a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.

Exceptions
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)
divideAndRemainderback to summary
public 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:double

value by which this MonetaryAmount is to be divided, and the remainder computed.

Returns:MonetaryAmount[]

a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.

Exceptions
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)
divideAndRemainderback to summary
public MonetaryAmount[] divideAndRemainder(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:Number

value by which this MonetaryAmount is to be divided, and the remainder computed.

Returns:MonetaryAmount[]

a two element MonetaryAmount array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.

Exceptions
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)
divideToIntegralValueback to summary
public 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:long

value by which this BigDecimal is to be divided.

Returns:MonetaryAmount

The integer part of this / divisor.

Exceptions
ArithmeticException:
if divisor==0
See Also
java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)
divideToIntegralValueback to summary
public 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:double

value by which this BigDecimal is to be divided.

Returns:MonetaryAmount

The integer part of this / divisor.

Exceptions
ArithmeticException:
if divisor==0
See Also
java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)
divideToIntegralValueback to summary
public MonetaryAmount divideToIntegralValue(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:Number

value by which this BigDecimal is to be divided.

Returns:MonetaryAmount

The integer part of this / divisor.

Exceptions
ArithmeticException:
if divisor==0
See Also
java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)
getContextback to summary
public 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:MonetaryContext

the MonetaryContext of this MonetaryAmount, never null .

getFactoryback to summary
public 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:MonetaryAmountFactory<? extends MonetaryAmount>

the new MonetaryAmountFactory with the given MonetaryAmount as its default values.

isEqualToback to summary
public boolean isEqualTo(MonetaryAmount amount)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

Parameters
amount:MonetaryAmount

the MonetaryAmount to be compared with this instance.

Returns:boolean

true if amount == this.

Exceptions
MonetaryException:
if the amount's currency is not equal to the currency of this instance.
isGreaterThanback to summary
public boolean isGreaterThan(MonetaryAmount amount)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

Parameters
amount:MonetaryAmount

the MonetaryAmount to be compared with this instance.

Returns:boolean

true if amount > this.

Exceptions
MonetaryException:
if the amount's currency is not equal to the currency of this instance.
isGreaterThanOrEqualToback to summary
public boolean isGreaterThanOrEqualTo(MonetaryAmount amount)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

Parameters
amount:MonetaryAmount

the MonetaryAmount to be compared with this instance.

Returns:boolean

true if amount >= this.

Exceptions
MonetaryException:
if the amount's currency is not equal to the currency of this instance.
isLessThanback to summary
public boolean isLessThan(MonetaryAmount amount)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

Parameters
amount:MonetaryAmount

the MonetaryAmount to be compared with this instance.

Returns:boolean

true if amount < this.

Exceptions
MonetaryException:
if the amount's currency is not equal to the currency of this instance.
isLessThanOrEqualToback to summary
public boolean isLessThanOrEqualTo(MonetaryAmount amt)

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

Parameters
amt:MonetaryAmount

the MonetaryAmount to be compared with this instance.

Returns:boolean

true if amount <= this.

Exceptions
MonetaryException:
if the amount's currency is not equal to the currency of this instance.
isNegativeback to summary
public default boolean isNegative()

Checks if a MonetaryAmount is negative.

Returns:boolean

true if signum() < 0.

isNegativeOrZeroback to summary
public default boolean isNegativeOrZero()

Checks if a MonetaryAmount is negative or zero.

Returns:boolean

true if signum() <= 0.

isPositiveback to summary
public default boolean isPositive()

Checks if a MonetaryAmount is positive.

Returns:boolean

true if signum() > 0.

isPositiveOrZeroback to summary
public default boolean isPositiveOrZero()

Checks if a MonetaryAmount is positive or zero.

Returns:boolean

true if signum() >= 0.

isZeroback to summary
public default boolean isZero()

Checks if an MonetaryAmount is zero.

Returns:boolean

true if signum() == 0.

multiplyback to summary
public MonetaryAmount multiply(long multiplicand)

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

Parameters
multiplicand:long

value to be multiplied by this MonetaryAmount.

Returns:MonetaryAmount

this * multiplicand

Exceptions
ArithmeticException:
if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
multiplyback to summary
public 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 java.lang.ArithmeticException is thrown if the input number's scale exceeds the capabilities.

Parameters
multiplicand:double

value to be multiplied by this MonetaryAmount. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.

Returns:MonetaryAmount

this * multiplicand

Exceptions
ArithmeticException:
if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
multiplyback to summary
public MonetaryAmount multiply(Number multiplicand)

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

Parameters
multiplicand:Number

value to be multiplied by this MonetaryAmount. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.

Returns:MonetaryAmount

this * multiplicand

Exceptions
ArithmeticException:
if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
negateback to summary
public MonetaryAmount negate()

Returns a MonetaryAmount whose value is -this, and whose scale is this.getContext().getMaxScale(), with rounding according to the context settings.

Returns:MonetaryAmount

-this, rounded as necessary.

Exceptions
ArithmeticException:
if rounding fails.
See Also
java.math.BigDecimal#negate()
plusback to summary
public MonetaryAmount 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:MonetaryAmount

this.

See Also
negate(), java.math.BigDecimal#plus()
queryback to summary
public 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.

Parameters
<R>
the type of the result
query:MonetaryQuery<R>

the query to invoke, not null

Returns:R

the query result, null may be returned (defined by the query)

remainderback to summary
public 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:long

value by which this MonetaryAmount is to be divided.

Returns:MonetaryAmount

this % divisor.

Exceptions
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.
remainderback to summary
public 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:double

value by which this MonetaryAmount is to be divided.

Returns:MonetaryAmount

this % divisor.

Exceptions
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.
remainderback to summary
public MonetaryAmount remainder(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:Number

value by which this MonetaryAmount is to be divided.

Returns:MonetaryAmount

this % divisor.

Exceptions
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.
scaleByPowerOfTenback to summary
public 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:int

the power.

Returns:MonetaryAmount

the calculated amount value.

Exceptions
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.
signumback to summary
public int signum()

Returns the signum function of this MonetaryAmount.

Returns:int

-1, 0, or 1 as the value of this MonetaryAmount is negative, zero, or positive.

stripTrailingZerosback to summary
public 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:MonetaryAmount

a numerically equal MonetaryAmount with any trailing zeros removed.

subtractback to summary
public 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:MonetaryAmount

value to be subtracted from this MonetaryAmount.

Returns:MonetaryAmount

this - subtrahend

Exceptions
ArithmeticException:
if the result exceeds the numeric capabilities of this implementation class, i.e. the MonetaryContext cannot be adapted as required.
withback to summary
public 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:MonetaryOperator

the operator to use, not null

Returns:MonetaryAmount

an object of the same type with the specified conversion made, not null