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
2 Answers 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.
Sign up to request clarification or add additional context in comments.
Comments
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
Avijit Karmakar
9,4566 gold badges48 silver badges61 bronze badges
Comments
lang-java
Localerequires it.