|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70137 json_encode/decode should use max precision for float like values by default
Submitted: 2015-07-25 22:16 UTC Modified: 2016-09-06 17:52 UTC
From: Assigned: bukka (profile)
Status: Closed Package: JSON related
PHP Version: Irrelevant 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:
New email:
PHP Version: OS:


 [2015-07-25 22:16 UTC]
json_encode/decode uses 'precision'.
It should use 'serialize.precision' to handle float like JSON numeric to be more precise.

Test script:
[yohgaki@dev PHP-master]$  php -r '$v = 10/3; var_dump(json_encode($v));'
string(15) "3.3333333333333"

[yohgaki@dev PHP-master]$  php -r '$v = 10/3; ini_set("precision", 17);var_dump(json_encode($v));'
string(18) "3.3333333333333335"

[yohgaki@dev PHP-master]$ php
var_dump(json_decode('{ "v" : 0.12345678901234567890 }'));
ini_set('precision', 17);
var_dump(json_decode('{ "v" : 0.12345678901234567890 }'));

object(stdClass)#1 (1) {
object(stdClass)#1 (1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-06 17:52 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: bukka
 [2016-09-06 17:52 UTC]
This has been already done in precise float value RFC implementaion (sorry forgot to update this bug report) that is part of 7.1
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC