round()
round(x,n)
x : Input number .
n :(optional ) Input number of digits after decimal .
Returns float or integer after rounding the input number upto the given decimal.
print(round(12.34567)) # 12
print(round(-12.34567)) # -12
print(round(12)) # 12
print(round(-12)) # -12
print(round(12.34567,2)) # 12.35
print(round(-12.34567,3)) # -12.346
To get better precision, decimal module can be used. Check this line. Expected output is not 3.68
print(round(3.675,2)) # 3.67
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
Python programming Basics ⇩