Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python round() function

Python round() function

Python Numbers Python Numbers


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


Return Value

Returns the rounded value of float x.


Example

The following shows examples of using the round() method:

Example

#!/usr/bin/python

print

"round(80.23456, 2) : "

,

round

(

80.23456

,

2

)

print

"round(100.000056, 3) : "

,

round

(

100.000056

,

3

)

print

"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 Python Numbers