- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
",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
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
Advertisements