2
我正在使用下面的代码以区域设置使用的正确表示法返回我的数字。例如,欧洲格式使用逗号而不是小数显示浮动/双打。虽然在设备上测试这些代码的工作,但不是在Droid X(所以我不知道还有多少其他手机也可能发生)。有没有人遇到这个问题和/或可能有解决方案?来自不同Android设备的不一致代码返回
下面是代码:
/**
* <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;
}
“Droid X上的代码不起作用”是什么意思?“代码工作时“mLocale”与“不起作用”是什么? –
在Droid X上,如果手机语言设置为西班牙语,上面的代码不会返回数字的正确表示法(逗号不是小数)。在我的应用程序之外,如果我进入“设置”并查看应用程序大小,手机不会使用逗号而不是小数点。 Nexus 1在两种情况下都显示逗号而不是小数。我会更新我的文章并包含图片。 – taraloca