This implementation uses a scale and 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 org. 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 NullPointerException
PrecisionScaleRoundedOperator#of(int, MathContext), org.javamoney.moneta.RoundedMoney , MonetaryOperator, BigDecimal#scale(), MathContext, BigDecimal#precision()
| Modifier and Type | Field and Description |
|---|---|
| private final MathContext | |
| private final PrecisionContextRoundedOperator | |
| private final int | |
| private final ScaleRoundedOperator |
| 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 int | |
| public static PrecisionScaleRoundedOperator | of(int scale, MathContext
the math context, not null. mathContext)Creates the rounded Operator from scale and roundingMode |
| public String |
| mathContext | back to summary |
|---|---|
| private final MathContext mathContext | |
| mathContextOperator | back to summary |
|---|---|
| private final PrecisionContextRoundedOperator mathContextOperator | |
| scale | back to summary |
|---|---|
| private final int scale | |
| scaleRoundedOperator | back to summary |
|---|---|
| private final ScaleRoundedOperator scaleRoundedOperator | |
| PrecisionScaleRoundedOperator | back to summary |
|---|---|
| private PrecisionScaleRoundedOperator(int scale, 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() | |
| getScale | back to summary |
|---|---|
| public int getScale() | |
| of | back to summary |
|---|---|
| public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext) 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-
| |