2

I know that there is already a similar question about this, but this one is a bit different.

Say we have a string, and we know it can be converted to a double, but we know nothing about the locale of it. Maybe its locale is English (with dot as separator) or French (with comma as separator), or something else.

So, how do I convert it to the right double value?

Umopepisdn
  • 807
  • 6
  • 16
william
  • 21
  • 2

2 Answers2

3

If you want to parse a number from the "users" (default) locale, then maybe this could help you:

double number = java.text.NumberFormat.getInstance().parse(stringNumber).doubleValue();
SlumpA
  • 882
  • 12
  • 24
0

I suppose if you wanted to brute force it, you could loop through NumberFormat.getAvailableLocales() and call NumberFormat.getInstance() for each one as shown here

Community
  • 1
  • 1