python - Generating a list with foating point values -
this question has answer here:
- is floating point math broken? 20 answers
i wish generate list these value:
[0,0.01,0.02...0.49]
and though correct way it:
[0.01*i in range(50)]
but horror observed following:
>>> 35*0.01 0.35000000000000003 >>> float("0.35") 0.35
what doing wrong? if understand correctly seems 35*0.01 not give closest floating point representation of 0.35 float("0.35") does.
to guarantee nearest valid floating point number, need start values exact. 0.01
isn't exact, 100.0
is.
[i/100.0 in range(50)]
Comments
Post a Comment