Nikola
Nikola

Reputation: 890

Double.parseDouble() Exception

I have this DecimalFormat:

DecimalFormat formatSci = new DecimalFormat("#.#########E0");

When I have

text.append(formatSci.format(answer));//answer is a double value

and after that:

double b = Double.parseDouble(text.toString());//text is something like 2.3333333E10

It throws NumberFormatException. What is wrong with this as apparently it works on android 4.4.4 and above and not on older versions?

Upvotes: 1

Views: 1930

Answers (1)

Priyank Patel
Priyank Patel

Reputation: 12362

This may happen because of your internal Locale specification.

Try using:

NumberFormat format = NumberFormat.getInstance(Locale.US);
Number number = format.parse(text.toString());
double d = number.doubleValue();
// OR
double d = Double.parseDouble(text.toString());

Upvotes: 1

Related Questions