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 | Field and Description |
|---|---|
| private final MathContext |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public MonetaryAmount | apply(MonetaryAmount amount)
Implements javax. Applies the operator on the given amount. |
| public MathContext | |
| public static PrecisionContextRoundedOperator | |
| public String |
| mathContext | back to summary |
|---|---|
| private final MathContext mathContext | |
| PrecisionContextRoundedOperator | back to summary |
|---|---|
| private PrecisionContextRoundedOperator(MathContext mathContext) | |
| apply | back to summary |
|---|---|
| public MonetaryAmount apply(MonetaryAmount amount) Implements javax. Doc from javax. Applies the operator on the given amount.
| |
| getMathContext | back to summary |
|---|---|
| public MathContext getMathContext() | |
| of | back to summary |
|---|---|
| public static PrecisionContextRoundedOperator of(MathContext mathContext) Creates the rounded Operator from mathContext
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |