python - Is there a way to show correct float value? -


is there way show float value in python 2 python 3 does?

code:

text = "print('hello, world')"  step = 100.0 / len(text) result = 0.0  _ in text:     result += step  print result print step print result == 100.0 

python 2.7.9

100.0 4.7619047619 false 

python 3.4.3

99.99999999999997 4.761904761904762 false 

i'm interested in result variable. not in step. sorry insufficient explanation want. :)

repr shows more digits (i'm guessing enough reproduce same float):

>>> print result 100.0 >>> print repr(result) 99.99999999999997 >>> result 99.99999999999997  >>> print step 4.7619047619 >>> print repr(step) 4.761904761904762 >>> step 4.761904761904762 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -