Round-off decimal points in Python

Nice trick i found in python.

Lets say you want to round off(truncate) huge float numbers. e.g.

The command used is “round”

x = 5.75845848484
r = round (x,5) # 5 is the number of digits you want to keep after the decimal point.
print r
#Result : 5.75846 #

r = round (x,2)

print r
# This would give me:
#Result : 5.76 #

Scroll to Top