简体   繁体   English

Java控制台(Eclipse,Mac)

[英]Java Console (Eclipse, Mac)

Output is 3,141590. 输出为3,141590。 Why it is not 3.141590? 为什么不是3.141590? I am using Eclipse (Java) on a Mac. 我在Mac上使用Eclipse(Java)。

public static void main(String[] args) {
    TextIO.putf("%f\n", 3.14159);
}

Thank you 谢谢

That is because of the Locale. 那是因为语言环境。 Try this 尝试这个

String.format(Locale.US, "%f\n", 3.14159);

For diferent Locales there are different formats for numbers, dates, encodings, etc. 对于不同的语言环境,数字,日期,编码等有不同的格式。

Comma(,) is coming instead of dot(.). 逗号(,)代替点(。)。 This is because of the locale. 这是由于区域设置。

I am giving you one example : 我举一个例子:

import java.text.NumberFormat;
import java.util.Locale;

public class JavaLocale
{
    public static void main(String[] args) 
    {
        Locale locale = new Locale("da", "DK");
        NumberFormat numberFormat = NumberFormat.getInstance(locale);
        String number = numberFormat.format(100.99);
        System.out.println(number);
    }
}

Output of this code : 此代码的输出:

100,99

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM