Edit report at http://bugs.php.net/bug.php?id=52324&edit=1
ID: 52324
User updated by: brunog at micro-examples dot com
Reported by: brunog at micro-examples dot com
Summary: bad result when adding two floats
Status: Bogus
Type: Bug
Package: *General Issues
Operating System: ubuntu
PHP Version: 5.2.14RC2
New Comment:
thank you for the quick reply
adding ini_set('precision',16); does not give correct result value :
0.09999999999999999
is it an echo() bug ?
0.0: is lexicographically before 0.1
0.09 + 0.01 = 0.0: is correct ascii saying
Previous Comments:
------------------------------------------------------------------------
[2010-07-13 00:39:21] [email protected]
prints 0.1 for me. You are probably hitting a floating point limitation
combined
with a precision setting problem in your environment. Try adding
ini_set('precision',16); to the top of your script and you will see.
------------------------------------------------------------------------
[2010-07-13 00:35:04] brunog at micro-examples dot com
Description:
------------
PHP Version => 5.2.4-2ubuntu5.10
can you please consider this short code ?
Test script:
---------------
<?php
$f1 = 0.09 ;
$f2 = 0.01 ;
$tot = $f1 + $f2 ;
echo("$tot\n") ;
?>
Expected result:
----------------
0.1
Actual result:
--------------
0.0:
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52324&edit=1