Bug #75690 [Opn->Nab]: PHP 7.1 changes precision when using json_encode() to encode floats

From: Date: Thu, 14 Dec 2017 21:05:49 +0000
Subject: Bug #75690 [Opn->Nab]: PHP 7.1 changes precision when using json_encode() to encode floats
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213110@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75690&edit=1 ID: 75690 Updated by: yohgaki@php.net Reported by: renan dot nannetti at gmail dot com Summary: PHP 7.1 changes precision when using json_encode() to encode floats -Status: Open +Status: Not a bug Type: Bug Package: JSON related Operating System: RHEL6 PHP Version: 7.1.12 Block user comment: N Private report: N New Comment: From PHP 7.1, precision handling differ. I suppose it's in UPGRADING. Use "valid" serialize_precision if you need specific precision. Previous Comments: ------------------------------------------------------------------------ [2017-12-14 19:13:55] renan dot nannetti at gmail dot com Description: ------------ Description: ------------ json_encode() is presenting rounding issues when trying to encode float values. Note: I'm using serialize_precision equals to -1 in my php.ini. Test script: --------------- <?php echo json_encode((floatval(-0.717655) - floatval(6.7173))); Expected result: ---------------- '-7.434955' Actual result: -------------- '-7.4349549999999995' ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75690&edit=1

« previous php.bugs (#213110) next »