note 48881 added to function.fmod

From: Date: Mon, 10 Jan 2005 19:44:49 +0000
Subject: note 48881 added to function.fmod
Groups: php.notes 
Request: Send a blank email to php-notes+get-83049@lists.php.net to get a copy of this message
fmod() does not mirror a calculator's mod function. For example, fmod(.25, .05) will return .05 instead of 0 due to floor(). Using the aforementioned example, you may get 0 by replacing floor() with round() in a custom fmod(). <? function fmod_round($x, $y) { $i = round($x / $y); return $x - $i * $y; } var_dump(fmod(.25, .05)); // float(0.05) var_dump(fmod_round(.25, .05)); // float(0) ?> ---- Manual Page -- http://www.php.net/manual/en/function.fmod.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48881 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48881&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48881&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48881&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48881&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48881&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48881&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48881&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83049) next »