The fmod Function

The fmod function calculates the fractional remainder of division.

Syntax

phpfmod(dividend, divisor);

Example

Let's find the remainder of dividing 4 by 1.2:

php<?php
  echo fmod(4, 1.2);
?>

Execution result:

php0.4

Example

Compare with what the % operator will output:

php<?php
  echo 4 % 1.2;
?>

Execution result:

php0

See Also

  • lesson division remainder,
    which explains the % operator
  • function round,
    which rounds fractions according to mathematical rules
  • function ceil,
    which rounds fractions up
  • function floor,
    which rounds fractions down