Michael
Michael

Reputation: 303

Java Console (Eclipse, Mac)

Output is 3,141590. Why it is not 3.141590? I am using Eclipse (Java) on a Mac.

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

Thank you

Upvotes: 1

Views: 105

Answers (2)

Avijit Karmakar
Avijit Karmakar

Reputation: 9388

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

Upvotes: 0

Matteo Pennetta
Matteo Pennetta

Reputation: 37

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.

Upvotes: 2

Related Questions