0

I'm having a little trouble undestanding one thing on python. I was trying to pick the rest of a division on a floating number, but i think i run into an error, because the result keeping coming wrong.

As an example, if I write this:

a = 2.9%2
b = 2.4%2
c = 2.1%2

print('{}\n{}\n{}'.format(a, b, c))

it returns

0.8999999999999999
0.3999999999999999
0.10000000000000009
  • 1
    @KenWhite: Python's modulo op _is_ for floating point as well, and it's very convenient. – DSM Jan 11 '18 at 03:11
  • @DSM: I knew I should have just stayed with the dupe link. Thanks. (Not sure I agree about *very convenient*, as FP modulo would seem to be pretty futile, but I stand corrected about it not existing.) – Ken White Jan 11 '18 at 03:17
  • Sorry, didn't found this post – Henrique Cezar Jan 11 '18 at 03:30

0 Answers0