Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display numbers with thousands separator in Java
To display number with thousands separator, set a comma flag.
System.out.printf( "%,d\n",78567);
The above would result.
78, 567
Let’s check for bigger numbers.
System.out.printf( "%,d\n", 463758);
The above would result.
463,758
Example
public class Demo {
public static void main( String args[] ) {
System.out.printf( "%,d\n", 95647 );
System.out.printf( "%,d\n", 687467 );
System.out.printf( "%,.2f\n", 7546.21 );
System.out.printf( "%,.2f\n", 463758.787 );
System.out.printf( "%,.2f", 123456.5 );
}
}
Output
95,647 687,467 7,546.21 463,758.79 123,456.50
Advertisements