Site icon Automation Dojos

Rounding Decimal Number With Java DecimalFormat

The DecimalFormat class has a method called setRoundingMode() which can be used for setting the rounding mode for DecimalFormat object. The setRoundingMode() accepts RoundingMode class object as the parameter.

You can pass any of the Enum constants available in the RoundingMode class as parameter to the setRoundingMode() method to achieve the desired rounding of decimal number.

The following example demonstrates rounding of the decimal number:

The above code produces the following output:

170180.24551 Rounded-UP 170,180.246
170180.24551 Rounded-DOWN 170,180.245 
Exit mobile version