UPDATE:在上面的問題中刪除「in Android 5.0」,因爲我覺得它與版本沒有任何關係,但取決於語言環境。爲什麼String.format(「%。2f」,10.0F)返回值10,00而不是10.00?
以下代碼的常見輸出爲10.00。但在Android 5.0中,它返回值10,00。
String value = String.format("%.2f", 10.0F);
System.out.println("Value is "+value); //For Console Output
Log.w("NumberClass.java","Value is "+value); //For Logcat Output
是
String.format("%.2f", 10.0F);
功能android的棒棒糖改變?如果那麼這個奇怪的行爲的解決方案是什麼?
我需要10.00作爲輸出。
它使用默認的語言環境。您應該使用特定的區域設置來初始化格式器。 –
[對我來說10,00是一個很好的... 10.00是壞的...](https://en.wikipedia.org/wiki/Decimal_mark#Countries_using_Arabic_numerals_with_decimal_comma) – Selvin