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.

8.574748485950
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 #

Neat!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.