Java String Formatting Java
This example shows how to apply comma in integers with String#printf()
String#printf()
Syntax: %,d (use comma in between % and d)
package com.logicbig.example.string;import java.util.Locale;public class StringPrintfIntegerComma { public static void main(String[] args) { //comma format System.out.printf("%,d%n", 1000000); System.out.printf("%,d%n", 100000); //for different locale System.out.printf(Locale.US, "%,d%n", 5000000); System.out.printf(Locale.GERMAN, "%,d%n", 6000000); }}
1,000,000100,0005,000,0006.000.000