Java Internalization - Grouping Digits


Advertisements

Using setGroupingSize() method of DecimalFormat, default grouping of numbers can be changed. Following example is illustrating the same.

IOTester.java

import java.text.DecimalFormat;

public class I18NTester {
   public static void main(String[] args) {
      double number = 121223232473.4567;

      DecimalFormat decimalFormat = new DecimalFormat();

      System.out.println(number);
      System.out.println(decimalFormat.format(number));
   

      decimalFormat.setGroupingSize(4);
      System.out.println(decimalFormat.format(number));
   
   }
}

Output

It will print the following result.

1.212232324734567E11
121,223,232,473.457
1212,2323,2473.457
Print

Useful Video Courses


Video

Java Date and Time Online Training

16 Lectures 2 hours

Malhar Lathkar

Video

Java Servlet Online Training

19 Lectures 5 hours

Malhar Lathkar

Video

JavaScript Online Training

25 Lectures 2.5 hours

Anadi Sharma

Video

Java Online Training

Most Popular

126 Lectures 7 hours

Tushar Kale

Video

Java Essential Training

119 Lectures 17.5 hours

Monica Mittal

Video

Java Essentials Online Training

76 Lectures 7 hours

Arnab Chakraborty

Advertisements