|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75690 PHP 7.1 changes precision when using json_encode() to encode floats
Submitted: 2017-12-14 19:13 UTC Modified: 2017-12-14 21:05 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: renan dot nannetti at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 7.1.12 OS: RHEL6
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: renan dot nannetti at gmail dot com
New email:
PHP Version: OS:


 [2017-12-14 19:13 UTC] renan dot nannetti at gmail dot com
json_encode() is presenting rounding issues when trying to encode float values.

Note: I'm using serialize_precision equals to -1 in my php.ini.

Test script:
echo json_encode((floatval(-0.717655) - floatval(6.7173)));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-14 21:05 UTC]
-Status: Open +Status: Not a bug
 [2017-12-14 21:05 UTC]
From PHP 7.1, precision handling differ. I suppose it's in UPGRADING.
Use "valid" serialize_precision if you need specific precision.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 06:01:30 2023 UTC