public final class PrecisionScaleRoundedOperator extends Object implements MonetaryOperator
RoundingMode and precision to does the rounding operations. The implementation will use both the scale and precision, in other words, the number of digits to the right of the decimal point and the number of digits.
The derived class will implements the RoundedMoney with this rounding monetary operator
int scale = 3;
int precision = 5;
MathContext mathContext = new MathContext(precision, RoundingMode.HALF_EVEN);
MonetaryOperator monetaryOperator = PrecisionScaleRoundedOperator.of(scale, mathContext);
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
MonetaryAmount result = monetaryOperator.apply(money); // BRL 35.346
Case the parameter in MonetaryOperator.apply(MonetaryAmount) be null, the apply will return a NullPointerExceptionRoundedMoney,
MonetaryOperator,
BigDecimal.scale(),
MathContext,
BigDecimal.precision()| Modifier and Type | Method and Description |
|---|---|
MonetaryAmount |
apply(MonetaryAmount amount) |
MathContext |
getMathContext() |
int |
getScale() |
static PrecisionScaleRoundedOperator |
of(int scale,
MathContext mathContext)
Creates the rounded Operator from scale and roundingMode
|
String |
toString() |
public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext)
mathContext - the math context, not null.MonetaryOperator using the scale and RoundingMode used in parameterNullPointerException - when the MathContext is nullIllegalArgumentException - if MathContext.getPrecision() is lesser than zeroIllegalArgumentException - if MathContext.getRoundingMode() is RoundingMode.UNNECESSARYRoundingModepublic MonetaryAmount apply(MonetaryAmount amount)
apply in interface MonetaryOperatorpublic int getScale()
public MathContext getMathContext()
Copyright © 2012–2020 JavaMoney. All rights reserved.