Java BigDecimal can have comma instead dot?

Jean Tehhe picture Jean Tehhe · Sep 10, 2013 · Viewed 42.4k times · Source

I have a string value that I want to assign to a BigDecimal. When I update the decimal value with a number like 100.23, it works fine but when I update it with a number like 100,23 the code throws an exception. Why is that?

Answer

No Idea For Name picture No Idea For Name · Sep 10, 2013

because you tried to put a "," in a number.

you can use this code to parse a number with comma:

NumberFormat.getNumberInstance(Locale.FRANCE).parse("265,858")

you should also use float or double if there is no particular reason you use decimal.