本文介绍了Java:浮点格式取决于语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我住在比利时。一般来说,在数学中,我们使用逗号来表示我们的小数:3,141592

这也是当我格式化浮点数时的结果。 b
$ b

  c> String.format(Locale.US,%f,floatValue)用于设置在格式化过程中使用的语言环境。


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:浮点格式取决于语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:50