Java:浮点格式取决于语言环境 [英] Java: Float Formatting depends on Locale
问题描述
这也是当我格式化浮点数时的结果。 b
$ b
System.out.println(String.format(%f,3.141592));
因此, 谢谢 。
被a ,
就像这样: 3,141592
。所以总是当我需要一个点时,我不得不添加如下所示: String.format(%f,3.14).replace(',','。'); $ c $所以,问题是:是否有一种方法来改变使Java中的每个格式化程序使用一个点,而不是逗号的区域设置?$ / $> $ / $> b
$ b
System.out。的println(Locale.getDefault());
打印
nl_BE
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.
这篇关于Java:浮点格式取决于语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!