I live in Belgium. And generally, in mathematics, we write our decimals with a comma like this: 3,141592
And that is also the result when I format the float.
System.out.println(String.format("%f", 3.141592));
So, the .
is replaced by a ,
like so: 3,141592
. So always when I need a point instead I have to add something like this: String.format("%f", 3.14).replace(',','.');
So, the question is: is there a way to change the Locale which makes every formatter in Java use a point, instead of comma?
Thanks
System.out.println(Locale.getDefault());
prints
nl_BE
Try using String.format(Locale.US, "%f", floatValue)
for just setting locale used during formatting.
A simple solution, but would be wide reaching across the entire Locale, would be to set the system Locale to US or UK. Example.
Locale.setDefault(Locale.US);
Since you have changed the question, then you simply specify the local with your print method.
System.out.println(String.format(Locale.US, "%f", 3.141592));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With