Bug #73680 [Nab]: json_encode on window error

From: Date: Thu, 08 Dec 2016 05:30:38 +0000
Subject: Bug #73680 [Nab]: json_encode on window error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205834@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73680&edit=1 ID: 73680 Updated by: yohgaki@php.net Reported by: xltxlm at qq dot com Summary: json_encode on window error Status: Not a bug Type: Bug Package: JSON related Operating System: Irrelevant PHP Version: 7.1.0 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2016-12-08 03:10:58] yohgaki@php.net 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 01:56:57] xltxlm at qq dot com Description: ------------ var_dump(json_encode([100.1])); Expected result: ---------------- string(7) "[100.1]" Actual result: -------------- string(20) "[100.09999999999999]" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73680&edit=1

« previous php.bugs (#205834) next »