parseDouble exception on Android while parsing a valid Double value

803 views Asked by At

The following code

if (Double.parseDouble(value) > 0)

throws the following exception

java.lang.NumberFormatException: Invalid double: "‎-2.49"


The logged value seems like a valid Double, what might cause this exception?

1

There are 1 answers

0
hotkey On

You seem to encounter a locale issue. That is, integer and fractional part separators differ in different locales, somewhere it's . and somewhere ,.

See that question, there's a probable solution. Use the locale which fits the best for you, for example Locale.US uses . as the separator.