Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
DecimalFormat setRoundingMode() method in Java
Next article icon

DecimalFormat setGroupingSize() method in Java

Last Updated : 01 Apr, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

The setGroupingSize() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to set the grouping size for this DecimalFormat instance or not. The grouping size is the number of integers in each group in the integral part of a decimal number. For example, the grouping size of 123, 456.78 is 3 and that of 12, 34, 56.78 is 2.

Syntax:

  public void setGroupingSize(int newSize)  

Parameters: The function accepts a single parameter newSize which is the size of the new group of integers to be set.

Return Value: The function does not returns any value.

Below is the implementation of the above function:

Program 1:




// Java program to illustrate the
// setGroupingSize() method
  
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Currency;
import java.util.Locale;
  
public class Main {
    public static void main(String[] args)
    {
  
        // Create the DecimalFormat Instance
        DecimalFormat deciFormat = new DecimalFormat();
  
        deciFormat.setGroupingSize(4);
  
        System.out.println(deciFormat.format(12345678.9));
    }
}
 
 
Output:
  1234, 5678.9  

Program 2:




// Java program to illustrate the
// setGroupingSize() method
  
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Currency;
import java.util.Locale;
  
public class Main {
    public static void main(String[] args)
    {
  
        // Create the DecimalFormat Instance
        DecimalFormat deciFormat = new DecimalFormat();
  
        deciFormat.setGroupingSize(2);
  
        System.out.println(deciFormat.format(12345678.9));
    }
}
 
 
Output:
  12, 34, 56, 78.9  

Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#setGroupingSize(int)



Next Article
DecimalFormat setRoundingMode() method in Java
author
gopaldave
Improve
Article Tags :
  • Java
  • Java-DecimalFormat
  • Java-Functions
  • Java-text package
Practice Tags :
  • Java

Similar Reads

  • DecimalFormat setRoundingMode() method in Java
    The setRoundingMode() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to set the RoundingMode to be used with this DecimalFormat instance to round-off the decimal digits. Syntax: public void setRoundingMode(RoundingMode roundingMode) Parameters: The function acce
    1 min read
  • DecimalFormat setMultiplier() method in Java
    The setMultiplier() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to a multiplier value to be used with this DecimalFormat instance. This multiplier value can be used while working with percent, percentile etc. For Example, for a multiplier value 10, the number
    1 min read
  • DecimalFormat setCurrency() method in Java
    The setCurrency() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to set the Currency for this DecimalFormat instance which will be used to formatting numbers. Syntax: public void setCurrency(Currency currency) Parameters: The function accepts a single parameter
    1 min read
  • DecimalFormat setPositiveSuffix() method in Java
    The setPositiveSuffix() method of the DecimalFormat class in Java is used to set a positive suffix value for this DecimalFormat instance. Syntax: public void setPositiveSuffix(String newValue) Parameters: This method a single parameter newValue which is the new value to be set as a positive suffix f
    1 min read
  • DecimalFormat setPositivePrefix() method in Java
    The setPositivePrefix() method of the DecimalFormat class in Java is used to set a positive prefix value for this DecimalFormat instance. Syntax: public void setPositivePrefix(String newValue) Parameters: This method a single parameter newValue which is the new value to be set as a positive prefix f
    1 min read
  • DecimalFormat setNegativeSuffix() method in Java
    The setNegativeSuffix() method of the DecimalFormat class in Java is used to set a negative suffix value for this DecimalFormat instance. Syntax: public void setNegativeSuffix(String newValue) Parameters: This method a single parameter newValue which is the new value to be set as a negative suffix f
    1 min read
  • DecimalFormat setNegativePrefix() method in Java
    The setNegativePrefix() method of the DecimalFormat class in Java is used to set a negative value of this DecimalFormat instance. Syntax: public void setNegativePrefix(String newValue) Parameters: This method a single parameter newValue which is the new value to be set as a negative prefix for this
    1 min read
  • DecimalFormat toPattern() method in Java
    The toPattern() method of the DecimalFormat class in Java is used to convert the format of the current pattern of this DecimalFormat to a string format. This converted string represents the pattern which is used to format the current state of this DecimalFormat instance. Syntax: public String toPatt
    2 min read
  • DecimalFormat setParseBigDecimal() method in Java
    The setParseBigDecimal() method of the DecimalFormat class in Java is used to set whether the parse() method of the DecimalFormat class will return a value of BigInteger type or not. If this method is set true, then the parse() method will return a BigDecimal value. Syntax: public void setParseBigDe
    1 min read
  • DecimalFormat setMinimumIntegerDigits() method in Java
    The setMinimumIntegerDigits() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to set the minimum number of digits allowed in the Integral part of a number. The Integral part of a number is the part displayed before the decimal(.) symbol. Syntax: public void setMi
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences