|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76934 json encode bug php 7.1 and above
Submitted: 2018-09-26 08:53 UTC Modified: 2018-09-26 09:36 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: grzesiek dot kesik at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 7.1.22 OS: any
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: grzesiek dot kesik at gmail dot com
New email:
PHP Version: OS:


 [2018-09-26 08:53 UTC] grzesiek dot kesik at gmail dot com
After some calculation json_encode encounter problem with casting numbers

Test script:

$n1 = 9.79;
$n2 = $n1 *100;

echo $n1;
echo '  ';
echo $n2;

echo ' ';

echo json_encode($n2);

echo ' ';
$n3 = 979;
echo json_encode($n3);

Expected result:
echo json_encode($n2);

should be equals 979

Actual result:
echo json_encode($n2);

is equal 978.9999999999999 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-26 08:55 UTC]
-Status: Open +Status: Not a bug
 [2018-09-26 08:55 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at
> Changelog
> 7.1.0  serialize_precision is used instead of precision when encoding double values.

Check your serialize_precision setting.
 [2018-09-26 09:30 UTC] grzesiek dot kesik at gmail dot com
According to comment, I have changed serialize_precision setting to 17 (as in php 7.0 For me it does not work. After restarting apache i still gets this rounding issue.
 [2018-09-26 09:36 UTC]
You will have to change it to a lower value such as 14 to restore the previous behavior.

However, you should seriously consider if that's really what you want -- you are actively corrupting your JSON output by reducing the precision with which floating point numbers are exported. Are you sure that is what you want to do? Most likely it is not.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 13:01:27 2024 UTC