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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC