Bug #75800 [Opn->Nab]: json_encode produces unexpected results with summed floats

From: Date: Thu, 11 Jan 2018 12:27:59 +0000
Subject: Bug #75800 [Opn->Nab]: json_encode produces unexpected results with summed floats
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213471@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75800&edit=1 ID: 75800 Updated by: requinix@php.net Reported by: yoch at yoch dot org Summary: json_encode produces unexpected results with summed floats -Status: Open +Status: Not a bug Type: Bug Package: JSON related Operating System: Ubuntu 16.04.3 LTS PHP Version: 7.2.1 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/function.json-encode.php > Changelog > 7.1.0 serialize_precision is used instead of precision when encoding double values. Previous Comments: ------------------------------------------------------------------------ [2018-01-11 11:50:03] yoch at yoch dot org Description: ------------ With default php.ini settings (serialize_precision = "-1" and precision = "14"), json_encode() produces inconsistent results. After setting serialize_precision to "14" serialization working as expected. Test script: --------------- php -r 'echo 2.09 + 0.4;' php -r 'echo json_encode(2.49);' php -r 'echo json_encode(2.09 + 0.4);' Expected result: ---------------- 2.49 2.49 2.49 Actual result: -------------- 2.49 2.49 2.4899999999999998 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75800&edit=1

« previous php.bugs (#213471) next »