Can someone pls explain what is going on here?

checkout this image I try to multiply 3 numbers in different order and they give different output but why???

Welcome to the forum, and welcome to floating-point math!

Here is another explanation from Julia Evans, who writes great zines about this stuff. The full zine is for sale but the intro might be enough for now.

thanks, but Its a bit complex

The bottom line is that you’ve discovered this kind of outcome can occur and as such you know to allow for such an outcome when you code an application.

Even experienced people can make mistakes. A couple of years I assumed that 2.0-b-c == 2.0-(b+c). It nearly always is, or at least close enough to not matter, but when dividing by the result, the difference, as in this example below (reported by a user), matters.

>>> 2.0 - 1.0 - 0.9999999999999999
>>> 2.0 - (1.0 + 0.9999999999999999)

Whoops, the user got an unexpected ZeroDivisionError.

1 Like