#30018 [Opn->Bgs]: multiplication bug (with float values)
| From: | rasmus@php.net | Date: | Tue, 07 Sep 2004 22:26:13 +0000 |
| Subject: | #30018 [Opn->Bgs]: multiplication bug (with float values) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65893@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:
Computers can only approximate floating point arithmetic to a given
precision level. Read
http://de.php.net/manual/en/language.types.float.php
Previous Comments:
------------------------------------------------------------------------
[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