#20688 [Bgs]: Math zero

From: Date: Tue, 20 May 2003 09:21:53 +0000
Subject: #20688 [Bgs]: Math zero
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-40016@lists.php.net to get a copy of this message
ID: 20688 Updated by: mgf@php.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: 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 For "why", please see http://www.php.net/language.types.float (the box headed "Floating point precision"). For more help on working with floating point numbers, please try a support forum such as php-general@lists.php.net. Previous Comments: ------------------------------------------------------------------------ [2003-05-19 13:08:54] rmendes at agencyweb dot net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#40016) next »