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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC