use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.
the class MonetaryOperatorsTest method shouldRoudingUsingRoundingMode.
@Test
public void shouldRoudingUsingRoundingMode() {
CurrencyUnit euro = Monetary.getCurrency("EUR");
MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = MonetaryOperators.rounding(RoundingMode.HALF_EVEN).apply(money);
assertNotNull(result);
assertEquals(result.getCurrency(), euro);
assertEquals(Double.valueOf(2.36), result.getNumber().doubleValue());
}
use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.
the class PercentOperatorTest method shouldReturnNegativeValue.
@Test
public void shouldReturnNegativeValue() {
CurrencyUnit currency = Monetary.getCurrency("BHD");
MonetaryAmount money = Money.parse("BHD -200.0");
MonetaryAmount result = operator.apply(money);
assertEquals(result.getCurrency(), currency);
assertEquals(result.getNumber().doubleValue(), -20.0);
}
use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.
the class PermilOperatorTest method shouldReturnNegativeValue.
@Test
public void shouldReturnNegativeValue() {
CurrencyUnit currency = Monetary.getCurrency("EUR");
MonetaryAmount money = Money.parse("EUR -2.35");
MonetaryAmount result = operator.apply(money);
assertEquals(result.getCurrency(), currency);
assertEquals(result.getNumber().doubleValue(), -0.0235);
}
use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.
the class PrecisionScaleRoundedOperatorTest method shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney.
@Test
public void shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney() {
int scale = 3;
int precision = 5;
CurrencyUnit real = Monetary.getCurrency("BRL");
BigDecimal valueOf = BigDecimal.valueOf(35.34567);
MonetaryAmount money = Money.of(valueOf, real);
MathContext mathContext = new MathContext(precision, RoundingMode.HALF_EVEN);
PrecisionScaleRoundedOperator monetaryOperator = PrecisionScaleRoundedOperator.of(scale, mathContext);
MonetaryAmount result = monetaryOperator.apply(money);
assertTrue(RoundedMoney.class.isInstance(result));
assertEquals(result.getCurrency(), real);
assertEquals(result.getNumber().getScale(), scale);
assertEquals(result.getNumber().getPrecision(), precision);
assertEquals(BigDecimal.valueOf(35.346), result.getNumber().numberValue(BigDecimal.class));
}
use of javax.money.CurrencyUnit in project jsr354-ri by JavaMoney.
the class ReciprocalOperatorTest method shouldReturnNegativeValue.
@Test
public void shouldReturnNegativeValue() {
CurrencyUnit currency = Monetary.getCurrency("EUR");
MonetaryAmount money = Money.parse("EUR -2.0");
MonetaryAmount result = operator.apply(money);
assertEquals(result.getCurrency(), currency);
assertEquals(result.getNumber().doubleValue(), -0.5);
}
Aggregations