Latest web development tutorials

Python3 round () function

Python3 digital Python3 digital


description

round () method returns the rounded value of the floating-point number x.


grammar

The following is the syntax round () method:

round( x [, n]  )

parameter

  • x - numeric expression.
  • n - numeric expression.

return value

Returns the rounded value of the floating-point number x.

Examples

The following illustrates the use of round () method Example:

#!/usr/bin/python3

print ("round(70.23456) : ", round(70.23456))
print ("round(56.659,1) : ", round(56.659,1))
print ("round(80.264, 2) : ", round(80.264, 2))
print ("round(100.000056, 3) : ", round(100.000056, 3))
print ("round(-100.000056, 3) : ", round(-100.000056, 3))

After running the above example output is:

round(70.23456) :  70
round(56.659,1) :  56.7
round(80.264, 2) :  80.26
round(100.000056, 3) :  100.0
round(-100.000056, 3) :  -100.0

Python3 digital Python3 digital