Site icon Automation Dojos

Format Decimal Numbers with Grouping Separator

The DecimalFormat class has a method called setGroupingSize() which sets how many digits of the integer part to group. Groups are separated by the grouping separator. Hence you can use setGroupingSize() method to change the default group digits number as you need.

The following example demonstrates setting grouping separator for integer part of the decimal number:

The above code produces the following output:

170180.24551 GroupSize(4) = 17,0180.246 
Exit mobile version