|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73680 json_encode on window error
Submitted: 2016-12-08 01:56 UTC Modified: 2016-12-08 05:30 UTC
From: xltxlm at qq dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 7.1.0 OS: Irrelevant
Private report: No CVE-ID: None
 [2016-12-08 01:56 UTC] xltxlm at qq dot com

Expected result:
string(7) "[100.1]"

Actual result:
string(20) "[100.09999999999999]"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-08 03:10 UTC]
-Status: Open +Status: Not a bug -Operating System: window +Operating System: Irrelevant
 [2016-12-08 03:10 UTC]
Use lower serialize_presision if you do not want this kind of outputs.

i.e. IEEE float value is not "precise" float value.
 [2016-12-08 05:30 UTC]
The reason behind this change.

JSON is cross platform serialization and most systems uses IEEE 754 for float. Older PHP JSON truncated float value by "precision" ini setting which is less precise with regard to IEEE 754. i.e. Older PHP was losing precision by default.

PHP 7.1 uses "serialize_precision" which is the same precision for most systems. Therefore, PHP 7.1 or later JSON can handle float value more precisely than before.

If users want to use the value displayed by "echo $float_val;", set the same "prevision" ini value to "serialize_precision". Please note that this affects serialize() also.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 15:01:26 2024 UTC