use of org.javamoney.moneta.RoundedMoney in project jsr354-ri by JavaMoney.
the class ScaleRoundedOperator method apply.
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
RoundedMoney roundedMoney = RoundedMoney.from(Objects.requireNonNull(amount));
BigDecimal numberValue = roundedMoney.getNumber().numberValue(BigDecimal.class);
BigDecimal numberRounded = numberValue.setScale(scale, roundingMode);
return RoundedMoney.of(numberRounded, roundedMoney.getCurrency(), this);
}
use of org.javamoney.moneta.RoundedMoney in project jsr354-ri by JavaMoney.
the class PrecisionContextRoundedOperator method apply.
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
RoundedMoney roundedMoney = RoundedMoney.from(Objects.requireNonNull(amount));
BigDecimal numberValue = roundedMoney.getNumber().numberValue(BigDecimal.class);
BigDecimal numberRounded = numberValue.round(mathContext);
return RoundedMoney.of(numberRounded, roundedMoney.getCurrency(), this);
}
use of org.javamoney.moneta.RoundedMoney in project jsr354-ri-bp by JavaMoney.
the class ScaleRoundedOperator method apply.
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
RoundedMoney roundedMoney = RoundedMoney.from(Objects.requireNonNull(amount));
BigDecimal numberValue = roundedMoney.getNumber().numberValue(BigDecimal.class);
BigDecimal numberRounded = numberValue.setScale(scale, roundingMode);
return RoundedMoney.of(numberRounded, roundedMoney.getCurrency(), this);
}
use of org.javamoney.moneta.RoundedMoney in project jsr354-ri-bp by JavaMoney.
the class PrecisionContextRoundedOperator method apply.
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
RoundedMoney roundedMoney = RoundedMoney.from(Objects.requireNonNull(amount));
BigDecimal numberValue = roundedMoney.getNumber().numberValue(BigDecimal.class);
BigDecimal numberRounded = numberValue.round(mathContext);
return RoundedMoney.of(numberRounded, roundedMoney.getCurrency(), this);
}
use of org.javamoney.moneta.RoundedMoney in project jsr354-ri by JavaMoney.
the class DefaultMonetaryRoundedFactoryTest method shouldCreateMonetaryAmount.
@Test
public void shouldCreateMonetaryAmount() {
MonetaryAmount monetaryAmount = factory.create(BigDecimal.TEN, real);
assertNotNull(monetaryAmount);
assertTrue(RoundedMoney.class.isInstance(monetaryAmount));
RoundedMoney roundedMoney = RoundedMoney.class.cast(monetaryAmount);
assertEquals(real, roundedMoney.getCurrency());
assertEquals(BigDecimal.TEN, roundedMoney.getNumber().numberValue(BigDecimal.class));
}
Aggregations