Python round() Function

Python 数字Python Numbers


Description

round()The method returns the rounded value of float x.


Syntax

The following is the syntax of the round() method:

round( x [, n]  )

Parameters

  • x -- Numeric expression.
  • n -- Numeric expression, indicating the number of decimal places.

Return Value

Returns the rounded value of float x.

Examples

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

Examples

#!/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)

After running the above examples, the output result is:

round(80.23456, 2) :  80.23
round(100.000056, 3) :  100.0
round(-100.000056, 3) :  -100.0

Python 数字Python Numbers

Other Extensions