Thursday, November 19, 2015

0.1 + 0.2 = = = 0.3 is not true

Just Open Google Chrome, press F12 and write the comparisation in the Console:

0.1 + 0.2 === 0.3

It's false? What? Why?
Well, it's not a JavaScript craziness. It's actually quite simple:

"Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, 0.1 + 0.2 != 0.3."

You can read more here (Floating Point Math) and see the behavior in other languages as well.