This page has a simple alert:
alert(185.3 + 12.37);
To me, that should equal 197.67
However, in the browsers I’ve tested (Chrome/Safari on OSX, FF on Win7) the answer is:
197.67000000000002
Why is that? Is this just a known bug or is there more to JavaScript addition than I realize?
javascript uses the
doubledatatype, which can’t, due to restricted binary places, express all decimal numbers accurately (not all numbers can be expressed with finite binary places). You can read more at wikipedia.