public final class ScaleRoundedOperator extends Object implements MonetaryOperator
RoundingMode to does the rounding operations. The implementation will use the scale, in other words, the number of digits to the right of the decimal point
The derived class will implements the RoundedMoney with this rounding monetary operator
MonetaryOperator monetaryOperator = ScaleRoundedOperator.of(scale, RoundingMode.HALF_EVEN);
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
MonetaryAmount result = monetaryOperator.apply(money); // BRL 35.3457
Case the parameter in MonetaryOperator.apply(MonetaryAmount) be null, the apply will return a NullPointerExceptionScaleRoundedOperator(int, RoundingMode),
RoundedMoney,
MonetaryOperator,
BigDecimal.scale()| Modifier and Type | Method and Description |
|---|---|
MonetaryAmount |
apply(MonetaryAmount amount) |
RoundingMode |
getRoundingMode() |
int |
getScale() |
static ScaleRoundedOperator |
of(int scale,
RoundingMode roundingMode)
Creates the rounded Operator from scale and roundingMode
|
String |
toString() |
public static ScaleRoundedOperator of(int scale, RoundingMode roundingMode)
scale - the scale to be usedroundingMode - the rounding mode to be usedMonetaryOperator using the scale and RoundingMode used in parameterNullPointerException - when the MathContext is nullRoundingModepublic MonetaryAmount apply(MonetaryAmount amount)
apply in interface MonetaryOperatorpublic int getScale()
public RoundingMode getRoundingMode()
Copyright © 2012–2020 JavaMoney. All rights reserved.