How to parse number string containing commas into an integer in java?

Is this comma a decimal separator or are these two numbers? In the first case you must provide Locale to NumberFormat class that uses comma as decimal separator:

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

This results in 265.858. But using US locale you’ll get 265858:

NumberFormat.getNumberInstance(java.util.Locale.US).parse("265,858")

That’s because in France they treat comma as decimal separator while in US – as grouping (thousand) separator.

If these are two numbers – String.split() them and parse two separate strings independently.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)