Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

seannn11

  • 4 years ago

>>> print(0.6//0.2) 2.0 WHY?!?

  • This Question is Closed
  1. carlsmith
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It's because of the way floats are stored internally. Because a mathematical float can have infinite precision, but, in real life, there's only so much memory to store one in, you get rounding errors. The expression (0.6/0.2), single slash, actually evaluates to 2.9999999999999996, not 3.0 as you'd expect. You are also using the floor division operator I think so that's where it'll be going wrong. The swapped the operators round between Python2 and Python3, so what / or // do are the opposite in each series.

  2. seannn11
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    how did u know it evaluated to 2.99999999999996

  3. JulieNewbie
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It is explained here http://docs.python.org/tutorial/floatingpoint.html

  4. bwCA
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://pastebin.com/vhM7Pcem

  5. carlsmith
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @seannn11 I just evaluated it interactively.

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy