0

I am confused with the simple computation below. Why the result is not 0.1?

3/5-2/4 = 0.6-0.5 = 0.1

Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/5 - 2/4
0.09999999999999998
drdot
  • 3,215
  • 9
  • 46
  • 81
  • Use `round()` to fix this. This is similar to JavaScript, where `0.3 - 0.2` is `0.19999999999999998` – shreyasm-dev Nov 01 '20 at 15:17
  • Also see https://en.wikipedia.org/wiki/IEEE_754#Basic_and_interchange_formats and https://stackoverflow.com/questions/588004/is-floating-point-math-broken (about JavaScript, but also applies to Python) – shreyasm-dev Nov 01 '20 at 15:18

0 Answers0