Convert any float number to Round number with Python
Sometimes you need to convert float number into round figure. Python has several way to do this
1. With round
1. With round
x = 34354.65756 round(x)
Output:34355.0
You can also define how many number after point. So look this
round(x,4)
Output: 34354.6576
round(x,2)
Output:34354.66
Another hard way to round float number, this code is found from Udacity. This code provide you no point after the round number. So look this code and code is very interesting
x=34354.65756 num=x+0.5 s= str(num) point = s.find('.') print s[:point]
Output:34355
Comments
Post a Comment