My Blog

My WordPress Blog

My Blog

My WordPress Blog

Grouping Digits

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

Example

Open Compiler

importjava.text.DecimalFormat;publicclassI18NTester{publicstaticvoidmain(String[] args){double number =121223232473.4567;DecimalFormat decimalFormat =newDecimalFormat();System.out.println(number);System.out.println(decimalFormat.format(number));   

  decimalFormat.setGroupingSize(4);System.out.println(decimalFormat.format(number));}}</code></pre>

Output

It will print the following result.

1.212232324734567E11
121,223,232,473.457
1212,2323,2473.457
Grouping Digits

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top