Jan Ajan
Jan Ajan

Reputation: 1591

How can I ensure that decimal separator will always be "."

In Polish regional setting decimal separator is ,. In english it is .. Maybe in other languages there are other separators. (Are there?).

I want to use BigDecimal's String constructor while reading an input file. In my file I want to use . as a decimal separator.

How can I ensure that I don't get NumberFormatException if a decimal separator of environment is not .?

Upvotes: 4

Views: 738

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502036

The BigDecimal constructor - like Double.parseDouble etc - always uses '.' as a decimal separator. It doesn't use the current culture at all, nor is there any way to specify a number format.

(It would be nice if this were clearly documented, admittedly...)

Upvotes: 7

Related Questions