php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cutmaster at fearlesss dot com
New email:
PHP Version: OS:

 

 [2007-03-26 08:02 UTC] 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) }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-26 10:29 UTC] tony2001@php.net
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.


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