5

I understand 15 mod 5 = 0 because there is no remainder from the division.

But why does 15.5 mod 5 == 0 also? Isn't there .5 remaining?

$time = "15.5";
$interval = 5.0;
if($time % $interval == 0)
    echo "it's time!";
else
    echo "not time";

//Outputs: it's time!
dukevin
  • 22,384
  • 36
  • 82
  • 111

1 Answers1

17

From the PHP docs:

Operands of modulus are converted to integers (by stripping the decimal part) before processing.

Use fmod if you want to preserve decimal remainders. (Thanks for the link, Oli Charlesworth, wasn't aware that such a function existed.)

Elliot Bonneville
  • 51,872
  • 23
  • 96
  • 123