Does modulus division only return integers? I need a float return. See the following:
var_dump(12 % 10); // returns 2, as expected
var_dump(11.5 % 10); // returns 1 instead of 1.5?
Yes. the %
operator returns an integer.
If you want a floating point result, use the fmod()
function instead.
See the manual.
Operands of modulus are converted to integers (by stripping the decimal part) before processing.
11.5 becomes 11.
11 % 10 = 1 remainder **1**
Your solution: fmod()
, as tom_yes_tom suggests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With