问题描述
我有一个在启动运行code以下两行的应用程序:
DecimalFormat的decim =新的DecimalFormat(#00);
返回Double.parseDouble(decim.format(totalNumberOfCredits));
当我启动应用程序,我的美国手机上,的decim.format值(totalNumberOfCredits)
是 .00
。
不过,在我的谷歌Play开发者控制台,我有一打崩溃,所有这一切看起来是这样的:
产生的原因:java.lang.NumberFormatException:无效的双,00
在java.lang.StringToReal.invalidReal(StringToReal.java:63)
在java.lang.StringToReal.parseDouble(StringToReal.java:269)
在java.lang.Double.parseDouble(Double.java:295)
难道真的可能是DecimalFormat的欧洲手机生产小数点逗号的版本?
Yes, absolutely. That's what it's meant to do, after all:
Note that this isn't a matter of a "European version of Android" - it's just a matter of using Android in a context where the default locale uses ,
as the decimal separator.
If you want to use the symbols for a particular locale, but using a specific pattern, you could use:
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(Locale.US);
DecimalFormat format = new DecimalFormat("#.00", symbols);
Having said that, it's not at all clear what you're trying to do in the first place - why would you format and then parse a number? You should almost always avoid string conversions when you don't really need them. Why not just convert it directly? (We don't know what totalNumberOfCredits
is, which doesn't help.)
这篇关于NumberFormatException的Android上的欧洲版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!