public final class MonetaryOperators extends Object
The class is thread-safe, which is also true for all functions returned by this class.
MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = operator.apply(money);
Or using:
MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = money.with(operator);
MonetaryAmount#with(MonetaryOperator)},
MonetaryOperator},
MonetaryOperator#apply(MonetaryAmount)}| Modifier and Type | Method and Description |
|---|---|
static javax.money.MonetaryOperator |
exchangeCurrency(javax.money.CurrencyUnit currencyUnit)
Deprecated.
|
static javax.money.MonetaryOperator |
majorPart()
Extract major part of
MonetaryAmount
This returns the monetary amount in terms of the minor units of the
currency, truncating the whole part if necessary. |
static javax.money.MonetaryOperator |
minorPart()
Extract minor part of
MonetaryAmount
This returns the monetary amount in terms of the minor units of the
currency, truncating the whole part if necessary. |
static javax.money.MonetaryOperator |
percent(BigDecimal decimal)
Gets the percentage of the amount.
|
static javax.money.MonetaryOperator |
percent(Number number)
Gets the percentage of the amount.
|
static javax.money.MonetaryOperator |
permil(BigDecimal decimal)
Gets the permil of the amount.
|
static javax.money.MonetaryOperator |
permil(Number number)
Returns the
percent(BigDecimal) converting
this number to BigDecimal and using the ConversionOperators.DEFAULT_MATH_CONTEXT |
static javax.money.MonetaryOperator |
permil(Number number,
MathContext mathContext)
Returns the
percent(BigDecimal) converting
this number to BigDecimal and using the MathContext in parameters |
static javax.money.MonetaryOperator |
reciprocal()
Gets the reciprocal of
MonetaryAmount
Gets the amount as reciprocal, multiplicative inverse value (1/n). |
static javax.money.MonetaryOperator |
rounding()
Rounding the
MonetaryAmount using CurrencyUnit.getDefaultFractionDigits()
and RoundingMode.HALF_EVEN. |
static javax.money.MonetaryOperator |
rounding(int scale)
Rounding the
MonetaryAmount using the scale informed
and RoundingMode.HALF_EVEN. |
static javax.money.MonetaryOperator |
rounding(RoundingMode roundingMode)
|
static javax.money.MonetaryOperator |
rounding(RoundingMode roundingMode,
int scale)
|
public static javax.money.MonetaryOperator reciprocal()
MonetaryAmount
Gets the amount as reciprocal, multiplicative inverse value (1/n).
MonetaryAmount money = Money.parse("EUR 2.0");
MonetaryAmount result = ConversionOperators.reciprocal().apply(money);//EUR 0.5
MonetaryOperatorpublic static javax.money.MonetaryOperator permil(BigDecimal decimal)
This returns the monetary amount in permil. For example, for 10% 'EUR 2.35' will return 0.235.
MonetaryAmount money = Money.parse("EUR EUR 2.35");
MonetaryAmount result = ConversionOperators.permil(BigDecimal.TEN).apply(money);//EUR 0.0235
MonetaryOperatorpublic static javax.money.MonetaryOperator permil(Number number)
percent(BigDecimal) converting
this number to BigDecimal and using the ConversionOperators.DEFAULT_MATH_CONTEXTnumber - to be converted to BigDecimalMonetaryOperator#permil(BigDecimal)}public static javax.money.MonetaryOperator permil(Number number, MathContext mathContext)
percent(BigDecimal) converting
this number to BigDecimal and using the MathContext in parametersnumber - to be converted to BigDecimalmathContext - the mathContext to be usedMonetaryOperator#permil(BigDecimal)}public static javax.money.MonetaryOperator percent(BigDecimal decimal)
This returns the monetary amount in percent. For example, for 10% 'EUR 2.35' will return 0.235.
MonetaryAmount money = Money.parse("EUR 200.0");
MonetaryAmount result = ConversionOperators.percent(BigDecimal.TEN).apply(money);//EUR 20.0
decimal - the value to percentMonetaryOperatorpublic static javax.money.MonetaryOperator percent(Number number)
number - to be used in percentMonetaryOperator#percent(BigDecimal)}public static javax.money.MonetaryOperator minorPart()
MonetaryAmount
This returns the monetary amount in terms of the minor units of the currency, truncating the whole part if necessary. For example, 'EUR 2.35' will return 'EUR 0.35', and 'BHD -1.345' will return 'BHD -0.345'.
MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = ConversionOperators.minorPart().apply(money);//EUR 0.35
MonetaryOperatorpublic static javax.money.MonetaryOperator majorPart()
MonetaryAmount
This returns the monetary amount in terms of the minor units of the currency, truncating the whole part if necessary. For example, 'EUR 2.35' will return 'EUR 0.35', and 'BHD -1.345' will return 'BHD -0.345'.
MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = ConversionOperators.majorPart().apply(money);//EUR 2.0
MonetaryOperatorpublic static javax.money.MonetaryOperator rounding()
MonetaryAmount using CurrencyUnit.getDefaultFractionDigits()
and RoundingMode.HALF_EVEN.
For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.
MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding().apply(money);//EUR 2.36
MonetaryOperatorpublic static javax.money.MonetaryOperator rounding(RoundingMode roundingMode)
MonetaryAmount using CurrencyUnit.getDefaultFractionDigits()
and RoundingMode.
For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.
MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding(RoundingMode.HALF_EVEN).apply(money);//EUR 2.35
roundingMode - rounding to be usedMonetaryOperatorpublic static javax.money.MonetaryOperator rounding(RoundingMode roundingMode, int scale)
MonetaryAmount using CurrencyUnit.getDefaultFractionDigits()
and RoundingMode.
For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.
MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding(RoundingMode.HALF_EVEN, 3).apply(money);//EUR 2.352
roundingMode - rounding to be usedscale - to be usedMonetaryOperatorpublic static javax.money.MonetaryOperator rounding(int scale)
MonetaryAmount using the scale informed
and RoundingMode.HALF_EVEN.
For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.
MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding(2).apply(money);//EUR 2.35
scale - scale to be usedMonetaryOperator@Deprecated public static javax.money.MonetaryOperator exchangeCurrency(javax.money.CurrencyUnit currencyUnit)
For example, 'EUR 2.35', using the currency 'USD' as exchange parameter, will return 'USD 2.35', and 'BHD -1.345', using the currency 'USD' as exchange parameter, will return 'BHD -1.345'.
Currency real = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.parse("EUR 2.355");
MonetaryAmount result = MonetaryOperators.exchangeCurrency(real).apply(money);//BRL 2.355
currencyUnit - currency to be usedMonetaryOperatorCopyright © 2012-2016 JavaMoney. All Rights Reserved.