Bug #16544 Updated: Floating point calculation bug or float() function bug
| From: | chris at owta dot net | Date: | Thu, 11 Apr 2002 10:31:56 +0000 |
| Subject: | Bug #16544 Updated: Floating point calculation bug or float() function bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-4648@lists.php.net to get a copy of this message | ||
ID: 16544
Updated by: chris@owta.net
Reported By: chris@owta.net
Status: Bogus
Bug Type: Math related
Operating System: Windows
PHP Version: 4.1.2
New Comment:
Why is this a support question? The bug is in the way the floor
function and the floating point internals in PHP are working. The floor
function is rounding a number down incorrectly.
Previous Comments:
------------------------------------------------------------------------
[2002-04-11 06:21:52] sander@php.net
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit http://www.php.net/support.php
------------------------------------------------------------------------
[2002-04-11 04:55:49] chris@owta.net
Here's the code
<?
$quantities = array(5000.00, 1000.00, 200.00);
$amount = 6200;
debug($quantities);
foreach ($quantities as $quantity) {
$divVal = ($amount/$quantity);
echo ++$i.". Quantity:\n".$quantity."<BR>";
echo "divVal: ".$divVal." - ".var_dump($divVal)."<BR>\n";
echo "Amount: ".$amount."\n";
if (floor($divVal) > 0) {
echo " [floored divVal is greater than zero]\n";
$amount = ($divVal - floor($divVal)) * $quantity;
}
echo "<BR><BR>";
}
?>
You'll see the floor function is operating incorrectly?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=16544&edit=1