Bug #70137 [NEW]: json_encode/decode should use max precision for float like values by default
| From: | yohgaki@php.net | Date: | Sat, 25 Jul 2015 22:16:14 +0000 |
| Subject: | Bug #70137 [NEW]: json_encode/decode should use max precision for float like values by default | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-194713@lists.php.net to get a copy of this message | ||
From: yohgaki
Operating system: any
PHP version: Irrelevant
Package: JSON related
Bug Type: Bug
Bug description:json_encode/decode should use max precision for float like values by default
Description:
------------
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
<?php
var_dump(json_decode('{ "v" : 0.12345678901234567890 }'));
ini_set('precision', 17);
var_dump(json_decode('{ "v" : 0.12345678901234567890 }'));
?>
object(stdClass)#1 (1) {
["v"]=>
float(0.12345678901235)
}
object(stdClass)#1 (1) {
["v"]=>
float(0.12345678901234568)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=70137&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70137&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70137&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70137&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70137&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70137&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70137&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70137&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70137&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70137&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70137&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70137&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70137&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70137&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70137&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70137&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70137&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70137&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70137&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70137&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70137&r=mysqlcfg