php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73643 float get rounded
Submitted: 2016-12-02 12:00 UTC Modified: 2016-12-03 00:04 UTC
From: remco dot pc at outlook dot com Assigned: cmb (profile)
Status: Not a bug Package: Arrays related
PHP Version: 5.6.28 OS: lsw (linux subsystem on windows)
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: remco dot pc at outlook dot com
New email:
PHP Version: OS:

 

 [2016-12-02 12:00 UTC] remco dot pc at outlook dot com
Description:
------------
when putting a float in a deep array, the float gets adjusted.




Test script:
---------------
$x = 3.4; //float

$tmp = array($x); 
var_dump($tmp);
/*
array (size=1)
  0 => float 3.4
*/
$tmp = array(array($x)) 
var_dump($tmp);
/*
array ( 0 => array ( 0 => 3.3999999999999999, ), )
*/

Expected result:
----------------
array ( 0 => array ( 0 => 3.4, ), )

Actual result:
--------------
array ( 0 => array ( 0 => 3.3999999999999999, ), )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-02 17:58 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-12-02 17:58 UTC] cmb@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://www.floating-point-gui.de/

Thank you for your interest in PHP.
 [2016-12-03 00:04 UTC] requinix@php.net
The value is not changing:
https://3v4l.org/gitkJ - same value everywhere
https://3v4l.org/9LqGu - what you see depends on the precision used
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC