dh-dev dh-dev - 1 month ago 16
Python Question

python division precision

I am aware of floating point being inaccurate and would like to know the best way to get

0.08354
instead of
(0.08353999999999999)
when I do the following in Python:

d = 8.354/100

print (d)

Answer

Use the builtin round() function:

>>> d = 8.354/100
>>> d
0.08353999999999999
>>> round(d, 6)
0.08354
>>>