I have a problem with float in Python...
I have this in a variable:
i = 9.600000000000001
And I would transform in this:
i = 9.60000
with five numbers after the decimal point and rounded.
I have a problem with float in Python...
I have this in a variable:
i = 9.600000000000001
And I would transform in this:
i = 9.60000
with five numbers after the decimal point and rounded.
>>> format(9.60000001,'.5f')
'9.60000'
>>>
from decimal import *
getcontext().prec = 6
i = 9.600000000000001
newI = Decimal(i)/1
print(newI)
returns 9.60000. However, float(newI) return 9.6, which is correct. The real question is do you want the actual value, in which case 9.60000 = 9.6, or just display 9.6 as 9.60000? In that case, the print solutions above will get you there.
You can use the second parameter in the round() function.
i = 9.600000000000001
i = round(i, 5)
print("%.5f" % i)
will return 9.60000.