|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40916 var_dump is not the friend of float numbers
Submitted: 2007-03-26 08:02 UTC Modified: 2007-03-26 10:29 UTC
From: cutmaster at fearlesss dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: cutmaster at fearlesss dot com
New email:
PHP Version: OS:


 [2007-03-26 08:02 UTC] cutmaster at fearlesss dot com
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");

Expected result:
array(2) { [0]=>  float(3700368445139) [1]=>  float(37003684447031) }

Actual result:
array(2) { [0]=>  float(3700368445140) [1]=>  float(37003684447000) }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-26 10:29 UTC]
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:
Thank you for your interest in PHP.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jan 17 21:01:24 2020 UTC