When I do the below operation, I am getting the result as below.
Actual : 5.9 / 100 = 0.059000000000000004
Expected : 5.9 / 100 = 0.059
Anyone has idea?
Thanks
When I do the below operation, I am getting the result as below.
Actual : 5.9 / 100 = 0.059000000000000004
Expected : 5.9 / 100 = 0.059
Anyone has idea?
Thanks
From MDN:
Numbers
Numbers in JavaScript are "double-precision 64-bit format IEEE 754 values", according to the spec. This has some interesting consequences. There's no such thing as an integer in JavaScript, so you have to be a little careful with your arithmetic if you're used to math in C or Java.
Also, watch out for stuff like:
0.1 + 0.2 == 0.30000000000000004;
In practice, integer values are treated as 32-bit ints, and some implementations even store it that way until they are asked to perform an instruction that's valid on a Number but not on a 32-bit integer. This can be important for bit-wise operations.
The standard arithmetic operators are supported, including addition, subtraction, modulus (or remainder) arithmetic, and so forth. There's also a built-in object that we did not mention earlier called Math that provides advanced mathematical functions and constants: