0

In Python 3 interpreter,

1//0.1
2//0.2
4//0.4

returns 9.0, but

5//0.5
3//0.3

returns 10.0. Is this rounding-off behavior correct?

enter image description here

Anuvrat Tiku
  • 1,616
  • 2
  • 17
  • 25
  • `//` is floor division. The floating point result of `1/0.1` is probably like `9.999...` which truncates down to `9` after you floor the result, which is what `//` does. – alkasm Aug 20 '19 at 23:18
  • @alkasm Not really. Check yourself with `f"{1/.1:.64f}"` – wim Aug 20 '19 at 23:19
  • @wim wait wtf, what's going on here then? I'm confused, since 0.1 is definitely over 0.1 in floating point format. – alkasm Aug 20 '19 at 23:22
  • 1
    This has a better explanation: [rounding errors in Python floor division](https://stackoverflow.com/q/38588815/674039) – wim Aug 20 '19 at 23:35

0 Answers0