#30018 [Opn->Bgs]: multiplication bug (with float values)
| From: | rasmus@php.net | Date: | Wed, 08 Sep 2004 04:05:59 +0000 |
| Subject: | #30018 [Opn->Bgs]: multiplication bug (with float values) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65904@lists.php.net to get a copy of this message | ||
ID: 30018
Updated by: rasmus@php.net
Reported By: phpbug at javision dot de
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: linux
PHP Version: 4.3.8
New Comment:
No chance. Triple-check your input.
Previous Comments:
------------------------------------------------------------------------
[2004-09-08 01:52:18] phpbug at javision dot de
i understand the rounding problem, but the bigger problem is that
402.83*1.16 returns 402.83 sometimes and sometimes it returns 467.2828.
so sometimes php multiplicates the number with 1.16 and sometimes it
doesn't
------------------------------------------------------------------------
[2004-09-08 00:26:11] rasmus@php.net
Computers can only approximate floating point arithmetic to a given
precision level. Read
http://de.php.net/manual/en/language.types.float.php
------------------------------------------------------------------------
[2004-09-07 23:32:09] phpbug at javision dot de
Description:
------------
sometimes php doesn't multiplicate float values and cuts the position
after the decimal point
Reproduce code:
---------------
//$aRegs[2][0] = 402.83 (regex match from website)
echo "<pre>\n";
var_dump($aRegs[2][0]);
echo "</pre>\n";
$zahl = $aRegs[2][0];
echo "<pre>\n";
var_dump($zahl);
echo "</pre>\n";
$zahl1 = doubleval($zahl);
echo "<pre>\n";
var_dump($zahl1);
echo "</pre>\n";
$zahl2 = (1.16*$zahl1);
echo "<pre>\n";
var_dump($zahl2);
echo "</pre>\n";
$zahl3 = (1.10*$zahl2);
echo "<pre>\n";
var_dump($zahl3);
echo "</pre>\n";
Expected result:
----------------
float(402.83)
float(402.83)
float(402.83)
float(467.2828)
float(514.01108)
Actual result:
--------------
float(402)
float(402)
float(402)
float(402)
float(402)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30018&edit=1