#20688 [Com]: Math zero
| From: | rmendes at agencyweb dot net | Date: | Mon, 19 May 2003 18:08:55 +0000 |
| Subject: | #20688 [Com]: Math zero | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-39987@lists.php.net to get a copy of this message | ||
ID: 20688
Comment by: rmendes at agencyweb dot net
Reported By: xqcheng at mail dot xjtu dot edu dot cn
Status: Bogus
Bug Type: Math related
Operating System: windows
PHP Version: 4.2.3
New Comment:
I have a similar problem :
<?
$a = 0.02;
$b = -0.02;
$total = $a +$b;
echo "$total";
?>
the output is :
Total : 5.55111512313E-017
Why ? and i am forced tio use bcmath ??
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2002-11-27 23:18:10] alan_k@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
there are quite a few bug reports on this.
adding floats can produce unpredicable results
you could try using bcmath or sprintf
$temp=-1.0;
for($i=0;$i<=10;$i++){
$temp=(float) sprintf(\"%.2f\",$temp+0.2);
echo \"<br>\".$temp;
}
------------------------------------------------------------------------
[2002-11-27 19:42:49] xqcheng at mail dot xjtu dot edu dot cn
<?php
$temp=-1.0;
for($i=0;$i<=10;$i++)
{
$temp=$temp+0.2;
echo "<br>".$temp;
}
?>
the output is :
-0.8
-0.6
-0.4
-0.2
-5.55111512313E-017
0.2
0.4
0.6
0.8
1
1.2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20688&edit=1