@Test public void shouldReturnMajorPartNegative() { MonetaryAmount monetaryAmount = Money.parse("BHD -1.345"); Long result = query.queryFrom(monetaryAmount); Long expected = -1345L; assertEquals(result, expected ); }
@Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); CurrencyUnit cur = amount.getCurrency(); int scale = cur.getDefaultFractionDigits(); if(scale<0){ scale = 0; } number = number.setScale(scale, RoundingMode.DOWN); return number.movePointRight(number.scale()).longValueExact(); }
ConvertMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); CurrencyUnit cur = amount.getCurrency(); int scale = cur.getDefaultFractionDigits(); if(scale<0){ scale = 0; } number = number.setScale(scale, RoundingMode.DOWN); return number.movePointRight(number.scale()).longValueExact(); } }
ConvertMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); CurrencyUnit cur = amount.getCurrency(); int scale = cur.getDefaultFractionDigits(); if(scale<0){ scale = 0; } number = number.setScale(scale, RoundingMode.DOWN); return number.movePointRight(number.scale()).longValueExact(); } ConvertMinorPartQuery(); }
ConvertMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); CurrencyUnit cur = amount.getCurrency(); int scale = cur.getDefaultFractionDigits(); if(scale<0){ scale = 0; } number = number.setScale(scale, RoundingMode.DOWN); return number.movePointRight(number.scale()).longValueExact(); } ConvertMinorPartQuery(); @Override Long queryFrom(MonetaryAmount amount); }
ConvertMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); CurrencyUnit cur = amount.getCurrency(); int scale = cur.getDefaultFractionDigits(); if(scale<0){ scale = 0; } number = number.setScale(scale, RoundingMode.DOWN); return number.movePointRight(number.scale()).longValueExact(); } ConvertMinorPartQuery(); @Override Long queryFrom(MonetaryAmount amount);  }