If 5.24/1
is 5.24
then 1*5.24 = 5.24
, so why is 5.24%1 = 0.24
? It should be 0, right? Because 1*5.24=5.24
? which leads to a zero in remainder?
Does mod only take the int part of a decimal to divide and produce a remainder?
If 5.24/1
is 5.24
then 1*5.24 = 5.24
, so why is 5.24%1 = 0.24
? It should be 0, right? Because 1*5.24=5.24
? which leads to a zero in remainder?
Does mod only take the int part of a decimal to divide and produce a remainder?
Yes, the %
operator for floating point numbers is so that the modulus is multiplied by an integer.
5.24 % 1 = 0.24 because
5.24 = 5*1 + 0.24
There is a separate issue with rounding error and what numbers can be represented exactly in binary floating point, which makes the result slightly different from 0.24.