I've found such an example of using String.format()
in a book:
package stringFormat;
public class Main {
public static void main(String[] args) {
String test = String.format("%, d", 1000000000);
System.out.println(test);
}
}
According to the book the output should be: 1,000,000,000
. But when I run the code I only get 1 000 000 000
without the commas. Why? how can I get it with commas?
Locale.setDefault(Locale.US);
before the call toformat
, the output would match that of the book. Seems that your OS has french-like number format rules.String.format
is locale-sensitive and that the actual output may differ.