本文介紹了如何用點(diǎn)格式化雙精度?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
如何將帶有 String.format
的 Double 格式化為在整數(shù)和小數(shù)部分之間加點(diǎn)??的字符串?
How do I format a Double with String.format
to String with a dot between the integer and decimal part?
String s = String.format("%.2f", price);
以上格式只用逗號(hào):",".
The above formats only with a comma: ",".
推薦答案
String.format(String, Object ...)
正在使用您的 JVM 的默認(rèn)語言環(huán)境.您可以使用 String.format(Locale, String, Object ...)
或 java.util.Formatter
直接.
String.format(String, Object ...)
is using your JVM's default locale. You can use whatever locale using String.format(Locale, String, Object ...)
or java.util.Formatter
directly.
String s = String.format(Locale.US, "%.2f", price);
或
String s = new Formatter(Locale.US).format("%.2f", price);
或
// do this at application startup, e.g. in your main() method
Locale.setDefault(Locale.US);
// now you can use String.format(..) as you did before
String s = String.format("%.2f", price);
或
// set locale using system properties at JVM startup
java -Duser.language=en -Duser.region=US ...
這篇關(guān)于如何用點(diǎn)格式化雙精度?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!