|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-09-27 05:00 UTC] ryan at ryanparman dot com
Description:
------------
When decoding a JSON string with json_decode(), a floating point precision error gets introduced.
Issue identified in PHP 5.5.17, and verified that it does NOT occur in 5.4.33.
Test script:
---------------
$data = json_decode('{"value": 4565.85}');
echo $data->value;
Expected result:
----------------
I expected `$data->value` to have a value of `4565.85`.
Actual result:
--------------
The actual value of `$data->value` is `4565.8500000000004`.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
So, I would like to better understand why two versions of PHP give me different results. ---- $ php --version PHP 5.5.17 (cli) (built: Sep 19 2014 00:50:57) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans $ php -i | grep -i precision precision => 14 => 14 serialize_precision => 17 => 17 ---- $ php --version PHP 5.4.33 (cli) (built: Sep 20 2014 16:20:03) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans $ php -i | grep -i precision precision => 14 => 14 serialize_precision => 100 => 100 ---- Could it be because the `serialize_precision` value is different?