Display numbers with thousands separator in Java


To display number with thousands separator, set a comma flag.

System.out.printf( "%,d
",78567);

The above would result.

78, 567

Let’s check for bigger numbers.

System.out.printf( "%,d
", 463758);

The above would result.

463,758

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      System.out.printf( "%,d
", 95647 );       System.out.printf( "%,d
", 687467 );       System.out.printf( "%,.2f
", 7546.21 );       System.out.printf( "%,.2f
", 463758.787 );       System.out.printf( "%,.2f", 123456.5 );    } }

Output

95,647
687,467
7,546.21
463,758.79
123,456.50

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 27-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements