Java big decimal number format exception

后端 未结 3 2082
傲寒
傲寒 2021-02-19 11:03

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

BigDecimal d = new BigDecimal(\"10934,375\");
3条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 11:34

    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");
    

提交回复
热议问题