我正在使用下面的代码以正确的表示法使用的方式返回我的数字。例如,欧洲格式使用逗号而不是小数显示浮点/双精度。在设备上进行测试时,这段代码可以正常工作,但不能在Droid X上进行测试(所以我想知道有多少其他手机也会出现这种情况)。有没有人碰到这个和/或可能有解决方案?
以下是代码:
/**
* <p>Converts doubles to twoDecimal points with proper notation per locale</p>
*
* @param double
* @return converted number to 2 decimal points with proper notation
*/
public static String getFormattedValue(double d) {
Locale mLocale = getResources().getConfiguration().locale;
String formattedString;
NumberFormat nf = NumberFormat.getNumberInstance(mLocale);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern("###,###.##");
formattedString = df.format(d);
return formattedString;
}
答案 0 :(得分:0)
我相信我明白了。如果我的手机的区域设置(语言)设置为西班牙语并显示小数,则该区域设置实际上是西班牙语(美国)。如果它显示逗号,那么它是欧洲西班牙语。我的Droid X列出了英语或西班牙语,而Nexus 1则有Espanol(Espana)和Espanol(Estados Unidos)。