php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16544 Floating point calculation bug or float() function bug
Submitted: 2002-04-11 04:55 UTC Modified: 2002-04-11 11:02 UTC
From: chris at owta dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.1.2 OS: Windows
Private report: No CVE-ID: None
 [2002-04-11 04:55 UTC] chris at owta dot 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 "&nbsp;[floored divVal is greater than zero]\n";
		$amount = ($divVal - floor($divVal)) * $quantity;
	}
	echo "<BR><BR>";
}


?>

You'll see the floor function is operating incorrectly?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-11 06:21 UTC] 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 06:31 UTC] chris at owta dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC