public final class RoundedMoney extends AbstractMoney implements java.lang.Comparable<javax.money.MonetaryAmount>, java.io.Serializable
MonetaryAmount based on
BigDecimal for the numeric representation.
As required by MonetaryAmount this class is final, thread-safe, immutable and
serializable.| Modifier and Type | Field and Description |
|---|---|
static javax.money.MonetaryContext |
DEFAULT_MONETARY_CONTEXT
The default
MonetaryContext applied. |
currency, monetaryContext| Modifier and Type | Method and Description |
|---|---|
RoundedMoney |
abs()
Returns a
MonetaryAmount whose value is the absolute value of this
MonetaryAmount, and whose scale is this.scale(). |
RoundedMoney |
add(javax.money.MonetaryAmount amount)
Returns a
MonetaryAmount whose value is (this +
amount), and whose scale is max(this.scale(),
amount.scale()). |
java.math.BigDecimal |
asNumberStripped()
Method that returns BigDecimal.ZERO, if
isZero(), and #number
stripTrailingZeros() in all other cases. |
<T> T |
asType(java.lang.Class<T> type) |
<T> T |
asType(java.lang.Class<T> type,
javax.money.MonetaryOperator adjuster) |
int |
compareTo(javax.money.MonetaryAmount o) |
RoundedMoney |
divide(double amount)
Returns a
MonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown. |
RoundedMoney |
divide(long amount)
Returns a
MonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown. |
RoundedMoney |
divide(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown. |
RoundedMoney[] |
divideAndRemainder(double amount)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
RoundedMoney[] |
divideAndRemainder(long amount)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
RoundedMoney[] |
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. |
RoundedMoney |
divideToIntegralValue(double divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
RoundedMoney |
divideToIntegralValue(long divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
RoundedMoney |
divideToIntegralValue(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
boolean |
equals(java.lang.Object obj) |
static RoundedMoney |
from(javax.money.MonetaryAmount amt) |
javax.money.CurrencyUnit |
getCurrency()
Returns the amount’s currency, modelled as
CurrencyUnit. |
protected javax.money.MonetaryContext |
getDefaultMonetaryContext()
Method to be implemented by superclasses to provide the default
MonetaryContext, when not explicit MonetaryContext is
available. |
javax.money.MonetaryAmountFactory<RoundedMoney> |
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. |
javax.money.MonetaryContext |
getMonetaryContext()
Access the
MathContext used by this instance. |
javax.money.NumberValue |
getNumber()
Simple accessor for the numeric part of a
MonetaryAmount. |
int |
getPrecision() |
int |
getScale() |
int |
hashCode() |
boolean |
isEqualTo(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isGreaterThan(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isLessThan(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isNegative()
Checks if a
MonetaryAmount is negative. |
boolean |
isNegativeOrZero()
Checks if a
MonetaryAmount is negative or zero. |
boolean |
isNotEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isPositive()
Checks if a
MonetaryAmount is positive. |
boolean |
isPositiveOrZero()
Checks if a
MonetaryAmount is positive or zero. |
boolean |
isZero()
Checks if an
MonetaryAmount is zero. |
RoundedMoney |
multiply(double amount)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()). |
RoundedMoney |
multiply(long amount)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()). |
RoundedMoney |
multiply(java.lang.Number multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()). |
RoundedMoney |
negate()
Returns a
MonetaryAmount whose value is (-this), and whose scale is
this.scale(). |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.math.BigDecimal number)
Translates a
BigDecimal value and a CurrencyUnit currency into a
Money. |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.math.BigDecimal number,
javax.money.MonetaryContext monetaryContext)
Translates a
BigDecimal value and a CurrencyUnit currency into a
Money. |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.math.BigDecimal number,
javax.money.MonetaryContext monetaryContext,
javax.money.MonetaryOperator rounding)
Translates a
BigDecimal value and a CurrencyUnit currency into a
Money. |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.math.BigDecimal number,
javax.money.MonetaryOperator rounding)
Translates a
BigDecimal value and a CurrencyUnit currency into a
Money. |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.lang.Number number)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.lang.Number number,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.lang.Number number,
javax.money.MonetaryContext monetaryContext,
javax.money.MonetaryOperator rounding)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(javax.money.CurrencyUnit currency,
java.lang.Number number,
javax.money.MonetaryOperator rounding)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(java.lang.String currencyCode,
java.lang.Number number)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(java.lang.String currencyCode,
java.lang.Number number,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(java.lang.String currencyCode,
java.lang.Number number,
javax.money.MonetaryContext monetaryContext,
javax.money.MonetaryOperator rounding)
Static factory method for creating a new instance of
RoundedMoney . |
static RoundedMoney |
of(java.lang.String currencyCode,
java.lang.Number number,
javax.money.MonetaryOperator rounding)
Static factory method for creating a new instance of
RoundedMoney . |
RoundedMoney |
plus()
Returns a
MonetaryAmount whose value is (+this), with rounding according to
the context settings. |
RoundedMoney |
pow(int n) |
<T> T |
query(javax.money.MonetaryQuery<T> query)
Queries this monetary amount for a value.
|
RoundedMoney |
remainder(double amount)
Returns a
MonetaryAmount whose value is (this % divisor). |
RoundedMoney |
remainder(long amount)
Returns a
MonetaryAmount whose value is (this % divisor). |
RoundedMoney |
remainder(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is (this % divisor). |
RoundedMoney |
scaleByPowerOfTen(int n)
Returns a
MonetaryAmount whose numerical value is equal to ( this *
10n). |
int |
signum()
Returns the signum function of this
MonetaryAmount. |
RoundedMoney |
stripTrailingZeros()
Returns a
MonetaryAmount which is numerically equal to this one but with any trailing
zeros removed from the representation. |
RoundedMoney |
subtract(javax.money.MonetaryAmount subtrahend)
Returns a
MonetaryAmount whose value is (this -
amount), and whose scale is max(this.scale(),
subtrahend.scale()). |
java.lang.String |
toString() |
RoundedMoney |
ulp() |
RoundedMoney |
with(javax.money.CurrencyUnit currency)
Creates a new Money instance, by just replacing the
CurrencyUnit. |
RoundedMoney |
with(javax.money.CurrencyUnit currency,
java.lang.Number amount) |
RoundedMoney |
with(javax.money.MonetaryOperator operator)
Returns an operated object of the same type as this object with the operation made.
|
RoundedMoney |
with(java.lang.Number amount) |
checkAmountParameter, checkNumberParameter, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getMathContextpublic static final javax.money.MonetaryContext DEFAULT_MONETARY_CONTEXT
MonetaryContext applied.public RoundedMoney abs()
javax.money.MonetaryAmountMonetaryAmount whose value is the absolute value of this
MonetaryAmount, and whose scale is this.scale().abs in interface javax.money.MonetaryAmountabs(this)public RoundedMoney add(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount whose value is (this +
amount), and whose scale is max(this.scale(),
amount.scale()).add in interface javax.money.MonetaryAmountamount - value to be added to this MonetaryAmount.this + amountpublic java.math.BigDecimal asNumberStripped()
isZero(), and #number
stripTrailingZeros() in all other cases.public <T> T asType(java.lang.Class<T> type)
public <T> T asType(java.lang.Class<T> type,
javax.money.MonetaryOperator adjuster)
public int compareTo(javax.money.MonetaryAmount o)
compareTo in interface java.lang.Comparable<javax.money.MonetaryAmount>public RoundedMoney divide(double amount)
javax.money.MonetaryAmountMonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown.divide in interface javax.money.MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this / divisorpublic RoundedMoney divide(long amount)
javax.money.MonetaryAmountMonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown.divide in interface javax.money.MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this / divisorpublic RoundedMoney divide(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown.divide in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this / divisorpublic RoundedMoney[] divideAndRemainder(double amount)
javax.money.MonetaryAmountMonetaryAmount 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.
divideAndRemainder in interface javax.money.MonetaryAmountamount - value by which this MonetaryAmount is to be divided, and the remainder
computed.MonetaryAmount array: the quotient (the result of
divideToIntegralValue) is the initial element and the remainder is the final
element.MonetaryAmount.divideToIntegralValue(double),
MonetaryAmount.remainder(double)public RoundedMoney[] divideAndRemainder(long amount)
javax.money.MonetaryAmountMonetaryAmount 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.
divideAndRemainder in interface javax.money.MonetaryAmountamount - value by which this MonetaryAmount is to be divided, and the remainder
computed.MonetaryAmount array: the quotient (the result of
divideToIntegralValue) is the initial element and the remainder is the final
element.MonetaryAmount.divideToIntegralValue(long),
MonetaryAmount.remainder(long)public RoundedMoney[] divideAndRemainder(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount 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.
divideAndRemainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided, and the remainder
computed.MonetaryAmount array: the quotient (the result of
divideToIntegralValue) is the initial element and the remainder is the final
element.MonetaryAmount.divideToIntegralValue(Number),
MonetaryAmount.remainder(Number)public RoundedMoney divideToIntegralValue(double divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. The preferred scale of the result is
(this.scale() -
divisor.scale()).divideToIntegralValue in interface javax.money.MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public RoundedMoney divideToIntegralValue(long divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. The preferred scale of the result is
(this.scale() -
divisor.scale()).divideToIntegralValue in interface javax.money.MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public RoundedMoney divideToIntegralValue(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. The preferred scale of the result is
(this.scale() -
divisor.scale()).divideToIntegralValue in interface javax.money.MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic static RoundedMoney from(javax.money.MonetaryAmount amt)
public javax.money.CurrencyUnit getCurrency()
AbstractMoneyCurrencyUnit.
Implementations may co-variantly change the return type to a more
specific implementation of CurrencyUnit if desired.getCurrency in interface javax.money.CurrencySuppliergetCurrency in interface javax.money.MonetaryAmountgetCurrency in class AbstractMoneynullMonetaryAmount.getCurrency()protected javax.money.MonetaryContext getDefaultMonetaryContext()
AbstractMoneyMonetaryContext, when not explicit MonetaryContext is
available.getDefaultMonetaryContext in class AbstractMoneyMonetaryContext, never null.public javax.money.MonetaryAmountFactory<RoundedMoney> getFactory()
javax.money.MonetaryAmountMonetaryAmountFactory, 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.
getFactory in interface javax.money.MonetaryAmountMonetaryAmountFactory with the given MonetaryAmount as its
default values.public javax.money.MonetaryContext getMonetaryContext()
MathContext used by this instance.getMonetaryContext in interface javax.money.MonetaryAmountgetMonetaryContext in class AbstractMoneyMathContext used, never null.MonetaryAmount.getMonetaryContext()public javax.money.NumberValue getNumber()
javax.money.MonetaryAmountMonetaryAmount. The representation type
returned should be the best matching according to the internal representation. In all cases
never any truncation should occur, so this method must be exact regarding the numeric value
externalized.getNumber in interface javax.money.MonetaryAmountgetNumber in interface javax.money.NumberSupplierMonetaryAmount, never null.public int getPrecision()
public int getScale()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean isEqualTo(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isEqualTo in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount == this.public boolean isGreaterThan(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThan in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount > this.public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThanOrEqualTo in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount >= this.public boolean isLessThan(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThan in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount < this.public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThanOrEqualTo in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount <= this.public boolean isNegative()
javax.money.MonetaryAmountMonetaryAmount is negative.isNegative in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() < 0.public boolean isNegativeOrZero()
javax.money.MonetaryAmountMonetaryAmount is negative or zero.isNegativeOrZero in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() <= 0.public boolean isNotEqualTo(javax.money.MonetaryAmount amount)
public boolean isPositive()
javax.money.MonetaryAmountMonetaryAmount is positive.isPositive in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() > 0.public boolean isPositiveOrZero()
javax.money.MonetaryAmountMonetaryAmount is positive or zero.isPositiveOrZero in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() >= 0.public boolean isZero()
javax.money.MonetaryAmountMonetaryAmount is zero.isZero in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() == 0.public RoundedMoney multiply(double amount)
javax.money.MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface javax.money.MonetaryAmountamount - value to be multiplied by this MonetaryAmount.this * multiplicandpublic RoundedMoney multiply(long amount)
javax.money.MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface javax.money.MonetaryAmountamount - value to be multiplied by this MonetaryAmount.this * multiplicandpublic RoundedMoney multiply(java.lang.Number multiplicand)
javax.money.MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface javax.money.MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic RoundedMoney negate()
javax.money.MonetaryAmountMonetaryAmount whose value is (-this), and whose scale is
this.scale().negate in interface javax.money.MonetaryAmount-this.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.math.BigDecimal number)
BigDecimal value and a CurrencyUnit currency into a
Money.number - numeric value of the Money.currency - currency unit of the Money.Money combining the numeric value and currency unit.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.math.BigDecimal number, javax.money.MonetaryContext monetaryContext)
BigDecimal value and a CurrencyUnit currency into a
Money.number - numeric value of the Money.currency - currency unit of the Money.monetaryContext - the MathContext to be used.Money combining the numeric value and currency unit.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.math.BigDecimal number, javax.money.MonetaryContext monetaryContext, javax.money.MonetaryOperator rounding)
BigDecimal value and a CurrencyUnit currency into a
Money.number - numeric value of the Money.currency - currency unit of the Money.mathContext - the MathContext to be used.rounding - The rounding to be applied.Money combining the numeric value and currency unit.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.math.BigDecimal number, javax.money.MonetaryOperator rounding)
BigDecimal value and a CurrencyUnit currency into a
Money.number - numeric value of the Money.currency - currency unit of the Money.rounding - The rounding to be applied.Money combining the numeric value and currency unit.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.lang.Number number)
RoundedMoney .currency - The target currency, not null.number - The numeric part, not null.RoundedMoney.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.lang.Number number, javax.money.MonetaryContext monetaryContext)
RoundedMoney .currency - The target currency, not null.number - The numeric part, not null.RoundedMoney.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.lang.Number number, javax.money.MonetaryContext monetaryContext, javax.money.MonetaryOperator rounding)
RoundedMoney .currency - The target currency, not null.number - The numeric part, not null.monetaryContext - the MonetaryContext to be used.rounding - The rounding to be applied.RoundedMoney.public static RoundedMoney of(javax.money.CurrencyUnit currency, java.lang.Number number, javax.money.MonetaryOperator rounding)
RoundedMoney .currency - The target currency, not null.number - The numeric part, not null.rounding - The rounding to be applied.RoundedMoney.public static RoundedMoney of(java.lang.String currencyCode, java.lang.Number number)
RoundedMoney .isoCurrencyCode - The target currency as ISO currency code.number - The numeric part, not null.RoundedMoney.public static RoundedMoney of(java.lang.String currencyCode, java.lang.Number number, javax.money.MonetaryContext monetaryContext)
RoundedMoney .isoCurrencyCode - The target currency as ISO currency code.number - The numeric part, not null.RoundedMoney.public static RoundedMoney of(java.lang.String currencyCode, java.lang.Number number, javax.money.MonetaryContext monetaryContext, javax.money.MonetaryOperator rounding)
RoundedMoney .isoCurrencyCode - The target currency as ISO currency code.number - The numeric part, not null.rounding - The rounding to be applied.RoundedMoney.public static RoundedMoney of(java.lang.String currencyCode, java.lang.Number number, javax.money.MonetaryOperator rounding)
RoundedMoney .isoCurrencyCode - The target currency as ISO currency code.number - The numeric part, not null.rounding - The rounding to be applied.RoundedMoney.public RoundedMoney plus()
javax.money.MonetaryAmountMonetaryAmount whose value is (+this), with rounding according to
the context settings.plus in interface javax.money.MonetaryAmountthis, rounded as necessary. A zero result will have a scale of 0.BigDecimal.plus()public RoundedMoney pow(int n)
public <T> T query(javax.money.MonetaryQuery<T> query)
javax.money.MonetaryAmountThis 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.
query in interface javax.money.MonetaryAmountT - the type of the resultquery - the query to invoke, not nullpublic RoundedMoney remainder(double amount)
javax.money.MonetaryAmountMonetaryAmount 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).
remainder in interface javax.money.MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this % divisor.public RoundedMoney remainder(long amount)
javax.money.MonetaryAmountMonetaryAmount 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).
remainder in interface javax.money.MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this % divisor.public RoundedMoney remainder(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount 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).
remainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this % divisor.public RoundedMoney scaleByPowerOfTen(int n)
javax.money.MonetaryAmountMonetaryAmount whose numerical value is equal to ( this *
10n). The scale of the result is (this.scale() - n).scaleByPowerOfTen in interface javax.money.MonetaryAmountn - the power.public int signum()
javax.money.MonetaryAmountMonetaryAmount.signum in interface javax.money.MonetaryAmountMonetaryAmount is negative, zero, or
positive.public RoundedMoney stripTrailingZeros()
javax.money.MonetaryAmountMonetaryAmount 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]stripTrailingZeros in interface javax.money.MonetaryAmountMonetaryAmount with any trailing zeros removed.public RoundedMoney subtract(javax.money.MonetaryAmount subtrahend)
javax.money.MonetaryAmountMonetaryAmount whose value is (this -
amount), and whose scale is max(this.scale(),
subtrahend.scale()).subtract in interface javax.money.MonetaryAmountsubtrahend - value to be subtracted from this MonetaryAmount.this - amountpublic java.lang.String toString()
toString in class java.lang.Objectpublic RoundedMoney ulp()
public RoundedMoney with(javax.money.CurrencyUnit currency)
CurrencyUnit.currency - the currency unit to be replaced, not nullMathContext, but the new
CurrencyUnit.public RoundedMoney with(javax.money.CurrencyUnit currency, java.lang.Number amount)
public RoundedMoney with(javax.money.MonetaryOperator operator)
javax.money.MonetaryAmountMonetaryAmountFactory instances: // converting from Money to MyMoney Money m = ...; MonetartyAmountFactoryf = MonetaryAmounts.getAmountFactory(MyMoney.class); MyMoney myMoney = f.setAmount(m).create();
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:
Hereby also the method signature on the implementation type must return the concrete type, to enable a fluent API, e.g.MonetaryAmount money = money.with(amountMultipliedBy(2)); money = money.with(amountRoundedToNearestWholeUnit());
public final class MyMoney implements MonetaryAmount{
...
public MyMoney with(MonetaryOperator operator){
...
}
...
}
with in interface javax.money.MonetaryAmountoperator - the operator to use, not nullpublic RoundedMoney with(java.lang.Number amount)