Python round() function
Description
round() The method returns the rounded value of the float x.
Syntax
The syntax of the round() method is as follows:
round( x [, n] )
Parameters
- x -- a numeric expression.
- n -- a numeric expression indicating the number of decimal places.
Return Value
Returns the rounded value of float x.
Example
The following shows examples of using the round() method:
Example
#!/usr/bin/python
"round(80.23456, 2) : "
,
round
(
80.23456
,
2
)
"round(100.000056, 3) : "
,
round
(
100.000056
,
3
)
"round(-100.000056, 3) : "
,
round
(
100.000056
,
3
)
Running the example above produces:
round(80.23456, 2) : 80.23
round(100.000056, 3) : 100.0
round(-100.000056, 3) : -100.0
Python Numbers