Java String Formatting Java This example shows how to apply comma in integers with 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); } }
Output1,000,000 100,000 5,000,000 6.000.000
|
|