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)
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)
If you want absolute precision, use Decimals:
>>> import decimal
>>> decimal.Decimal('8.354') / 10
Decimal('0.8354')
Use the builtin round()
function:
>>> d = 8.354/100
>>> d
0.08353999999999999
>>> round(d, 6)
0.08354
>>>