Re: Unexpected result in floor function

From: Date: Mon, 17 Nov 2003 14:21:05 +0000
Subject: Re: Unexpected result in floor function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-169936@lists.php.net to get a copy of this message
ruben wrote:
Hi: Why is the "floor" function returning 27564 instead of 27565 in this script? PHP version is 4.2.2. Thanks! Ruben. #!/usr/bin/php -q <?php $b = 275.65 * 100;
$b = (int)$b; /* $b was a floating point number with value something like 27564.9999989, when displayed it shows correctly 27565, but in calculations 27564.9999989 is used. Q: Do you know why pentiums are faster than 486 processors? A: Because 486 computes, pentium guesses. */
echo "\n\nb= ".$b;
echo "\nfloor(b)= ".floor($b);    // Incorrect. why 27564?
$b = 27565; echo "\n\nb= ".$b;
echo "\nfloor(b)= ".floor($b)."\n\n";    // Correct
?>


« previous php.general (#169936) next »