This implementation uses a scale and 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 NullPointerException
ScaleRoundedOperator(MathContext), RoundedMoney, MonetaryOperator, BigDecimal#scale()
| Modifier and Type | Field and Description |
|---|---|
| private final RoundingMode | |
| private final int |
| 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 RoundingMode | |
| public int | |
| public static ScaleRoundedOperator | of(int
the scale to be used scale, RoundingMode the rounding mode to be used roundingMode)Creates the rounded Operator from scale and roundingMode |
| public String |
| roundingMode | back to summary |
|---|---|
| private final RoundingMode roundingMode | |
| scale | back to summary |
|---|---|
| private final int scale | |
| ScaleRoundedOperator | back to summary |
|---|---|
| private ScaleRoundedOperator(int scale, RoundingMode roundingMode) | |
| apply | back to summary |
|---|---|
| public MonetaryAmount apply(MonetaryAmount amount) Implements javax. Doc from javax. Applies the operator on the given amount.
| |
| getRoundingMode | back to summary |
|---|---|
| public RoundingMode getRoundingMode() | |
| getScale | back to summary |
|---|---|
| public int getScale() | |
| of | back to summary |
|---|---|
| public static ScaleRoundedOperator of(int scale, RoundingMode roundingMode) Creates the rounded Operator from scale and roundingMode
| |
| 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-
| |