Bug #54730 [Opn->Bgs]: comparison float
| From: | rasmus@php.net | Date: | Sat, 14 May 2011 00:49:59 +0000 |
| Subject: | Bug #54730 [Opn->Bgs]: comparison float | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-160721@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54730&edit=1
ID: 54730
Updated by: rasmus@php.net
Reported by: dancho at hahpss dot com
Summary: comparison float
-Status: Open
+Status: Bogus
Type: Bug
Package: Math related
Operating System: Linux
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
Try adding ini_set('precision',32); to the top of your test script and
it should
be clear why these are not equal.
Previous Comments:
------------------------------------------------------------------------
[2011-05-13 20:01:09] dancho at hahpss dot com
Description:
------------
view result
Test script:
---------------
<?php
$v=2.06667;
echo var_dump($v*100000)."\n";
echo var_dump(round($v*100000,0));
echo "\nIs equal ? ";
echo ($v*100000==round($v*100000,0)) ? "true" : "false";
?>
Expected result:
----------------
float(206667)
float(206667)
Is equal ? true
Actual result:
--------------
float(206667)
float(206667)
Is equal ? false
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54730&edit=1