PHP fmod() Function – Returns Floating‑Point Remainder of Division

This article explains PHP's fmod() function, detailing its syntax, parameter meanings, return value, and provides a practical code example that demonstrates how it calculates the floating‑point remainder of a division operation.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP fmod() Function – Returns Floating‑Point Remainder of Division

The article describes the PHP fmod() function, which returns the floating‑point remainder of dividing one number by another.

Syntax float fmod ( float $x, float $y ) Parameters $x – the dividend. $y – the divisor (must be non‑zero).

Return value

The function returns the remainder r such that x = i * y + r, where i is an integer; the sign of r matches the sign of x and its absolute value is less than y.

Example

<?php
$x = 5.7;
$y = 1.3;
$r = fmod($x, $y);
// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7
?>

The output comment shows that $r equals 0.5, confirming the function’s behavior.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendmath functionfloating-point remainderfmod
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.