public final class PrecisionContextRoundedOperator extends Object implements javax.money.MonetaryOperator
This implementation uses a MathContext to does the rounding operations. The implementation will use the precision, in other words, the total number of digits in a number
The derived class will implements the RoundedMoney with this rounding monetary operator
MathContext mathContext = new MathContext(4, RoundingMode.HALF_EVEN);
MonetaryOperator monetaryOperator = PrecisionContextRoundedOperator.of(mathContext);
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
MonetaryAmount result = monetaryOperator.apply(money); // BRL 35.35
Case the parameter in MonetaryOperator.apply(MonetaryAmount) be null, the apply will return a NullPointerException
PrecisionContextRoundedOperator#of(MathContext)},
RoundedMoney},
MonetaryOperator},
BigDecimal#precision()}| Modifier and Type | Method and Description |
|---|---|
javax.money.MonetaryAmount |
apply(javax.money.MonetaryAmount amount) |
MathContext |
getMathContext() |
static PrecisionContextRoundedOperator |
of(MathContext mathContext)
Creates the rounded Operator from mathContext
|
String |
toString() |
public static PrecisionContextRoundedOperator of(MathContext mathContext)
mathContext - MonetaryOperator using the MathContext used in parameterNullPointerException - when the MathContext is nullIllegalArgumentException - when the MathContext.getPrecision() is lesser than zeroIllegalArgumentException - when the mathContext is MathContext.getRoundingMode() is RoundingMode.UNNECESSARYMathContext}public javax.money.MonetaryAmount apply(javax.money.MonetaryAmount amount)
apply in interface javax.money.MonetaryOperatorpublic MathContext getMathContext()
Copyright © 2012-2016 JavaMoney. All Rights Reserved.