Python round() Function
Rounds numbers to the specified number of digits past the decimal point (default is 0 digits past the decimal point.)
Syntax
Python
Copy Code
round(number = None)
Parameters
Parameter | Description |
---|---|
number |
Required. A numeric value to be rounded off. |
ndigits |
Optional. The number of decimal places to round the value. The default is None, meaning round to a whole number. |
Example
Python
Copy Code
pi = 3.14159265359 print(round(pi)) print(round(pi, 2))
Output
3 3.14