Consider following snippet:
 a = 0.1; b = 0.2; c = 0.3; alert(a + (b + c) === (a + b) + c); 
What will be the output of the code?
Explanation
a + (b + c) = 0.6 (a + b) + c = 0.6000000000000001 Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. JavaScript uses 64-bit floating point representation, which is the same as Java's double. The crux of the problem is that numbers are represented in this format as a whole number times a power of two; rational numbers (such as 0.1, which is 1/10) whose denominator is not a power of two cannot be exactly represented.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты