@Test public void shouldReturnPositiveValue() { CurrencyUnit currency = Monetary.getCurrency("EUR"); MonetaryAmount money = Money.parse("EUR 2.3523"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), 2.35); }
@Override public MonetaryAmount apply(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); CurrencyUnit currency = amount.getCurrency(); int scale = scaleOptional.orElse(currency.getDefaultFractionDigits()); BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode); return amount.getFactory().setNumber(value).create(); }
RoundingMonetaryAmountOperator implements MonetaryOperator { @Override public MonetaryAmount apply(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); CurrencyUnit currency = amount.getCurrency(); int scale = scaleOptional.orElse(currency.getDefaultFractionDigits()); BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode); return amount.getFactory().setNumber(value).create(); } }
RoundingMonetaryAmountOperator implements MonetaryOperator { @Override public MonetaryAmount apply(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); CurrencyUnit currency = amount.getCurrency(); int scale = scaleOptional.orElse(currency.getDefaultFractionDigits()); BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode); return amount.getFactory().setNumber(value).create(); } RoundingMonetaryAmountOperator();  RoundingMonetaryAmountOperator(RoundingMode roundingMode);  RoundingMonetaryAmountOperator(RoundingMode roundingMode, int scale); }
RoundingMonetaryAmountOperator implements MonetaryOperator { @Override public MonetaryAmount apply(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); CurrencyUnit currency = amount.getCurrency(); int scale = scaleOptional.orElse(currency.getDefaultFractionDigits()); BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode); return amount.getFactory().setNumber(value).create(); } RoundingMonetaryAmountOperator();  RoundingMonetaryAmountOperator(RoundingMode roundingMode);  RoundingMonetaryAmountOperator(RoundingMode roundingMode, int scale); @Override MonetaryAmount apply(MonetaryAmount amount); }
RoundingMonetaryAmountOperator implements MonetaryOperator { @Override public MonetaryAmount apply(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); CurrencyUnit currency = amount.getCurrency(); int scale = scaleOptional.orElse(currency.getDefaultFractionDigits()); BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode); return amount.getFactory().setNumber(value).create(); } RoundingMonetaryAmountOperator();  RoundingMonetaryAmountOperator(RoundingMode roundingMode);  RoundingMonetaryAmountOperator(RoundingMode roundingMode, int scale); @Override MonetaryAmount apply(MonetaryAmount amount);  }