|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: xltxlm at qq dot com
New email:
PHP Version: OS:


 [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-2023 The PHP Group
All rights reserved.
Last updated: Sun Dec 03 20:01:28 2023 UTC