Python round() Function

Instance

Round the number to only two decimal places:

x = round(3.1415926, 2)
print(x)

Run Instance

Definition and Usage

The round() function returns a floating-point number, which is the rounded version of the specified number with the specified number of decimal places.

The default number of decimal places is 0, indicating that the function will return the nearest integer.

Syntax

round(number, digits)

Parameter Value

Parameter Description
number Required. The number to be rounded.
digits Optional. The number of decimal places to use when rounding. The default is 0.

More Examples

Instance

Round to the nearest integer:

x = round(3.1415926)
print(x)

Run Instance