Problem with fmod() function

From: Date: Tue, 30 Dec 2003 11:46:19 +0000
Subject: Problem with fmod() function
Groups: php.general 
Request: Send a blank email to php-general+get-173478@lists.php.net to get a copy of this message
Hello, My understanding from the documentation is that the fmod() function should work with floating point numbers however the following snippet of code: <?php //php 4.3 on Linux $x = 1.05; $y = 0.05; echo "x: $x <br>"; echo "y: $y <br>"; echo "fmod: " . fmod($x, $y) . "<br>"; ?> outputs the following: x: 1.05 y: 0.05 fmod: 0.05 I would have expected to get an answer of 0 i.e. no remainder. It works fine for whole numbers. Can any one shed any light on this please? Thank you. Regards, Andy P.S. I tried using the following function but I get the same results: function fmodAddOn($x,$y) { $i = floor($x/$y); // r = x - i * y return $x - $i*$y; }

« previous php.general (#173478) next »