-224 / -37.333333333333336 = 6
-224 % -37.333333333333336 = -37.33333333333332
(-224 / -37.333333333333336) % 1 = 0
Why doesn't %
return 0
if the first result is 6
?
And why isn't the result a float
in the third calculation?
-224 / -37.333333333333336 = 6
-224 % -37.333333333333336 = -37.33333333333332
(-224 / -37.333333333333336) % 1 = 0
Why doesn't %
return 0
if the first result is 6
?
And why isn't the result a float
in the third calculation?
All numbers in JavaScript are 64-bit floating point numbers. Just because it doesn't display the number as 0.0
doesn't mean it's not a double.
According to WolframAlpha:
-224 / -37.333333333333336 = 5.9999999999999995714285...
Due to accuracy limitations / rounding in floating point division, the division results in 6 in JavaScript.
The modulo operation, however, correctly sees that -37.3… doesn't quite fit into -224 six times. That means that the other 99.99…% of -37.33… is a leftover after the division, which corresponds to result of the modulo operation.
Hence, you get almost, but not quite, the divisor back.