Search in sources :

Example 1 with RoundedMoney

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);
}
Also used : RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal)

Example 2 with RoundedMoney

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);
}
Also used : RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal)

Example 3 with RoundedMoney

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);
}
Also used : RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal)

Example 4 with RoundedMoney

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);
}
Also used : RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal)

Example 5 with RoundedMoney

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));
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)6 RoundedMoney (org.javamoney.moneta.RoundedMoney)6 MonetaryAmount (javax.money.MonetaryAmount)2 Test (org.testng.annotations.Test)2