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