public final class MonetaryOperators extends Object
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 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 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 MonetaryOperator |
percent(BigDecimal decimal)
Gets the percentage of the amount.
|
static MonetaryOperator |
percent(Number number)
Gets the percentage of the amount.
|
static MonetaryOperator |
permil(BigDecimal decimal)
Gets the permil of the amount.
|
static MonetaryOperator |
permil(Number number)
Returns the
percent(BigDecimal) converting
this number to BigDecimal and using the DEFAULT_MATH_CONTEXT |
static MonetaryOperator |
permil(Number number,
MathContext mathContext)
Returns the
percent(BigDecimal) converting
this number to BigDecimal and using the MathContext in parameters |
static MonetaryOperator |
reciprocal()
Gets the reciprocal of
MonetaryAmount
Gets the amount as reciprocal, multiplicative inverse value (1/n). |
static MonetaryOperator |
rounding()
Rounding the
MonetaryAmount using CurrencyUnit.getDefaultFractionDigits()
and RoundingMode.HALF_EVEN. |
static MonetaryOperator |
rounding(int scale)
Rounding the
MonetaryAmount using the scale informed
and RoundingMode.HALF_EVEN. |
static MonetaryOperator |
rounding(RoundingMode roundingMode)
|
static MonetaryOperator |
rounding(RoundingMode roundingMode,
int scale)
|
public static 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 MonetaryOperator permil(BigDecimal decimal)
MonetaryAmount money = Money.parse("EUR EUR 2.35");
MonetaryAmount result = ConversionOperators.permil(BigDecimal.TEN).apply(money);//EUR 0.0235
MonetaryOperatorpublic static MonetaryOperator permil(Number number)
percent(BigDecimal) converting
this number to BigDecimal and using the DEFAULT_MATH_CONTEXTnumber - to be converted to BigDecimalMonetaryOperatorpermil(BigDecimal)public static 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 usedMonetaryOperatorpermil(BigDecimal)public static MonetaryOperator percent(BigDecimal decimal)
MonetaryAmount money = Money.parse("EUR 200.0");
MonetaryAmount result = ConversionOperators.percent(BigDecimal.TEN).apply(money);//EUR 20.0
decimal - the value to percentMonetaryOperatorpublic static MonetaryOperator percent(Number number)
number - to be used in percentMonetaryOperatorpercent(BigDecimal)public static 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 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 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 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 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 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 usedMonetaryOperatorCopyright © 2012–2020 JavaMoney. All rights reserved.