I'm working on something that requires some very simple arithmetic, but some of the results that come up are just mind-boggling.
For example, paste the following in Chrome / Firefox / Opera DevTools console:
(211.8 - 0.5) + 0.8
The result should be 212.1
.... but I keep getting 212.10000000000002
Although I can work around it using toFixed()
or Math.ceil()
etc. I would like to know what causes things like that to happen.
I may have passed it off as a JSVM bug on a particular JS runtime, but it happens on multiple JS engines.
Any JS / JSVM gurus care to enlighten me?