Shikarn-O Shikarn-O - 1 year ago 106
Java Question

How to format Double with dot?

How do I format a Double with

to String with a dot between the integer and decimal part?

String s = String.format("%.2f", price);

The above formats only with a comma: ",".

Answer Source

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

// 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 ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download