Is there any explanation for this strange behavior tested on chrome, firefox, ie. when you do 8.9 * 3 you get 26.700000000000003
console.log(8.9 * 3);
any help?
Is there any explanation for this strange behavior tested on chrome, firefox, ie. when you do 8.9 * 3 you get 26.700000000000003
console.log(8.9 * 3);
any help?
You have discovered the "joy" of doing real number math in computers.
JavaScript uses 64-bit IEEE-754 numbers; this leaves 64 bits to represent all the possible real numbers that it knows about.
They are represented as what we call "floating point" numbers, which just means that the computer stores the characteristic (integer part) and the mantissa (fractional part) in those 64-bits. The integer part, to the left of the decimal, is easily dealt with. The mantissa is a bit trickier, and it is stored, basically as a fraction in binary.
Unfortunately, such binary fractions cannot always represent decimal quantities with 100% accuracy....and you have discovered one such case.