How to format a number for String by putting "."?

3

I was trying to format a number by putting points to make reading easier.

Only with the dot does not work, but it works with commas.

Ex:

String s = String.format("%. d", 123456);

System.out.println(s);
    
asked by anonymous 02.05.2017 / 04:19

1 answer

4

%, d is the thousands separator, and will use the default location of the JVM unless you specify otherwise. To force the Brazilian location that uses dot as separator, unlike the American that uses comma you can:

String.format(new Locale("pt"),"%,d",1234567)
    
02.05.2017 / 04:50