- Trending Categories
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
Add grouping specifiers for large numbers in Java
For using the Formatter class, import the following package −
import java.util.Formatter;
We can group specifiers as shown below −
Formatter f = new Formatter(); f.format("%,.2f", 38178.9889);
The above sets thousands separator and 2 decimal places.
The following is an example −
Example
import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); f.format("%d", 50); System.out.println(f); f = new Formatter(); f.format("%,.2f", 38178.9889); System.out.println(f); } }
Output
50 38,178.99
- Related Articles
- C++ Program to add few large numbers
- Space format specifiers in Java
- How to add/subtract large numbers using Python?
- How to generate large random numbers in Java?
- Divisible by 37 for large numbers in C++ Program
- Grouping of same kind of numbers in JavaScript
- Find Last Digit of a^b for Large Numbers in C++
- Handling large numbers in C++?
- Large Fibonacci Numbers in C#
- Java Program to Add Two Numbers
- Format specifiers in C
- Java Program to Add the two Numbers
- Java Program to Add Two Complex numbers
- Sum of two large numbers in C++
- What are the differences between protected and default access specifiers in Java?

Advertisements