Search code examples
javaexceptionbigdecimal

Java big decimal number format exception


Why does the code below throw a java number format exception?

BigDecimal d = new BigDecimal("10934,375");

Solution

  • The problem is that constructor of BigDecimal requires decimal number format where decimals come right after decimal dot . instead of decimal comma , so the right format for this specific case would be:

    BigDecimal d = new BigDecimal("10934.375");