fmod
Returns the remainder of a division of floats.
Syntax
fmod(float $num1, float $num2): floatParameters
| Parameter | Type | Description |
|---|---|---|
| $num1 | float | The dividend. |
| $num2 | float | The divisor. |
Return value
floatThe remainder.
Examples
The remainder for floats:
<?php
echo fmod(7.5, 2), "\n";
echo (int) 7.5 % 2;Output:
1.5
1Notes
The % operator works with integers only: the fraction has to be dropped explicitly, otherwise PHP raises a deprecation notice. Floats need fmod().
See also
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.