|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30330 fmod() does not return the correct value.
Submitted: 2004-10-05 19:46 UTC Modified: 2004-10-05 20:40 UTC
From: dbauleo at terra dot com dot br Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.9 OS: Windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: dbauleo at terra dot com dot br
New email:
PHP Version: OS:


 [2004-10-05 19:46 UTC] dbauleo at terra dot com dot br
I used the fmod() function with float numbers, and it was an exact division, so it was supposed to return 0, instead of it, the Y value was returned.

Reproduce code:

  echo fmod(396456.06, 56636.58);


Expected result:
fmod(396456.06, 56636.58) = 0

Actual result:
fmod(396456.06, 56636.58) = 56636.58

function f_mod($x,$y)
$i = floor($x / $y);
$a = $x - $i * $y;
return $a;

f_mod(396456.06, 56636.58) = 0


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-05 20:40 UTC]
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.
Thank you for your interest in PHP.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 03:05:45 2022 UTC