converting a float to decimal type in Python
I have an array that grows with each iteration of a loop:
for i in range(100):
frac[i] = some fraction between 0 and 1 with many decimal places
This all works fine. When I check the type(frac[i]), I am told that it is
'numpy.float64'.
For my code to be as precise as I need it to be, I need to use the decimal
module and change each frac[i] to the decimal type.
I updated my code:
for i in range(100):
frac[i] = some fraction between 0 and 1 with many decimal places
frac[i] = decimal.Decimal(frac[i])
But when I check the type, I am STILL told that frac[i] is 'numpy.float64'.
I have managed to change other variables to decimal in this way before, so
I wonder if you could tell me why this doesn't seem to work.
Thank you.
No comments:
Post a Comment