-1

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?

E_net4
  • 27,810
  • 13
  • 101
  • 139
BatKnight
  • 37
  • 1
  • 5

1 Answers1

2

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.

Joni
  • 108,737
  • 14
  • 143
  • 193