-1

I try to get the result of -0.15 modulo 5 in PHP.
Following codes always return 0.

$mod = ((-0.15) % 5)
$mod = (-0.15 % 5)
$mod = gmp_mod("-0,15", "5");
$mod = gmp_mod(-0.15, 5);

When I type "-0.15 mod 5" into google, it returns: 4.85

What is wrong with the code I use in PHP?

Kia
  • 301
  • 3
  • 11

1 Answers1

0

According to http://php.net/language.operators.arithmetic, "Operands of modulus are converted to integers (by stripping the decimal part) before processing."

So $mod = 0 % 5, which would be 0.

malcanso
  • 100
  • 2
  • 7