0

Assuming I have three line of python code

text = "0.965"
value = float(text)
print value

My question is, when they display the output, why my python show 0.9649999999999999 instead if 0.965. I know I can use round to get rid of this problem, but I just wondering why this is the case? I though I should just get the 0.965?

Thanks for you answering.

JLTChiu
  • 983
  • 3
  • 12
  • 28
  • 1
    Erm, I meant to use [Python rounding error with float numbers](http://stackoverflow.com/q/5997027) instead. But both are fine. :-) – Martijn Pieters Feb 22 '13 at 17:01
  • see here [http://docs.python.org/2/tutorial/floatingpoint.html](http://docs.python.org/2/tutorial/floatingpoint.html) for an explanation as well as how to use `Decimal` to enforce the desired accuracy – tzelleke Feb 22 '13 at 17:05

0 Answers0