Search code examples
java-moneyjsr354

Monetary.of(new BigDecimal("100.00"), "EUR") prints "EUR 1E+2"


So here's the question: why this:

Monetary.of(new BigDecimal("100.00"), "EUR") 

prints "EUR 1E+2", but any other decimal != .00 will print correct:

Monetary.of(new BigDecimal("100.01"), "EUR") 

"EUR 100.01"???


Solution

  • OK,

    it looks like the MonetaryAmount calls toString() which will call the engineeringString of the BigDecimal. The correct way to print a MonetaryAmount is to format it:

    MonetaryFormats.getAmountFormat(Locale.getDefault()).format(Money.of(source.getValue(), source.getCurrency().getUid()))