简体   繁体   English

Double.parseDouble()异常

[英]Double.parseDouble() Exception

I have this DecimalFormat: 我有这个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. 它引发NumberFormatException。 What is wrong with this as apparently it works on android 4.4.4 and above and not on older versions? 这有什么问题,因为它显然适用于android 4.4.4及更高版本,而不适用于旧版本?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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