Python Tutorial Python Advanced Python References Python Libraries

Python round() Function



The Python round() function returns specified number rounded to the specified number of decimal places.

Syntax

round(number, n)

Parameters

number Required. A number.
n Optional. number of decimal places to use for rounding the number. default is 0.

Example: Absolute value of a number

In the example below, round() function returns a given number rounded to the specified number of decimal places.

#rounding to zero decimal places
MyNumber = 3.1428
print(round(MyNumber))

#rounding to 2 decimal places
MyNumber = 3.1428
print(round(MyNumber, 2))

The output of the above code will be:

3
3.14

❮ Python Built-in Functions