1

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

asked Sep 13, 2015 at 16:25
4
  • 1
    Because your Locale requires it. Commented Sep 13, 2015 at 16:27
  • with Windows it is 3.141590 why? Commented Sep 13, 2015 at 16:31
  • Your windows has another Locale i guess then Commented Sep 13, 2015 at 16:38
  • Ok, thank you for that Commented Sep 13, 2015 at 16:42

2 Answers 2

2

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.

answered Sep 13, 2015 at 16:55
Sign up to request clarification or add additional context in comments.

Comments

0

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
answered Sep 13, 2015 at 17:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.