Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

fmod

Returns the remainder of a division of floats.

Syntax

fmod(float $num1, float $num2): float

Parameters

ParameterTypeDescription
$num1floatThe dividend.
$num2floatThe 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
1

Notes

The % operator works with integers only: the fraction has to be dropped explicitly, otherwise PHP raises a deprecation notice. Floats need fmod().

See also

  • intdiv — Performs integer division.
  • round — Rounds a number to a given number of digits.

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.