#40916 [Opn->Bgs]: var_dump is not the friend of float numbers
| From: | tony2001@php.net | Date: | Mon, 26 Mar 2007 10:29:47 +0000 |
| Subject: | #40916 [Opn->Bgs]: var_dump is not the friend of float numbers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-110789@lists.php.net to get a copy of this message | ||
ID: 40916
Updated by: tony2001@php.net
Reported By: cutmaster at fearlesss dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Linux
PHP Version: 5.2.1
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://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2007-03-26 08:02:26] cutmaster at fearlesss dot com
Description:
------------
Using float in arrays with var_dump returns rounded results, which is
definitly not the stored numbers...
And if you try an echo sprintf('%.0f',$value[0]) you'll get the good
value...
Too bad :(
Reproduce code:
---------------
$value = array((float)"3700368445139",(float)"37003684447031");
var_dump($value);
Expected result:
----------------
array(2) { [0]=> float(3700368445139) [1]=> float(37003684447031) }
Actual result:
--------------
array(2) { [0]=> float(3700368445140) [1]=> float(37003684447000) }
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40916&edit=1