简体   繁体   中英

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?

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM