sfu*_*ger 105
String.format(String, Object ...)正在使用您的JVM的默认语言环境.您可以使用String.format(Locale, String, Object ...)或java.util.Formatter直接使用任何区域设置.
String s = String.format(Locale.US, "%.2f", price);
Run Code Online (Sandbox Code Playgroud)
要么
String s = new Formatter(Locale.US).format("%.2f", price);
Run Code Online (Sandbox Code Playgroud)
要么
// 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);
Run Code Online (Sandbox Code Playgroud)
要么
// set locale using system properties at JVM startup
java -Duser.language=en -Duser.region=US ...
Run Code Online (Sandbox Code Playgroud)