Python error in basic subtraction? [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Python rounding error with float numbers python maths is wrong I can't get Python to correctly do the subtraction 1 - 0.8 and assign it. It keeps coming up with the incorrect answer, 0.19999999999999996. I explored a bit: sq = {} sub = {} for i in range(1000): sq[str(i/1000.)+'**2']=((i/1000.)**2) sub['1-'+str(i/1000.)]=(1.0-(i/1000.)) and discovered that this error happens with a somewhat random group of the