Bug #75254 [Opn->Nab]: json_encode float

From: Date: Mon, 25 Sep 2017 13:55:49 +0000
Subject: Bug #75254 [Opn->Nab]: json_encode float
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211351@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75254&edit=1 ID: 75254 Updated by: requinix@php.net Reported by: 845861050 at qq dot com Summary: json_encode float -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: centos 6.5 PHP Version: 7.1.9 Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. Then don't set serialize_precision = -1. Previous Comments: ------------------------------------------------------------------------ [2017-09-25 13:11:16] 845861050 at qq dot com Description: ------------ <?php $a=1.2; $b=1; $c=$a-$b; echo json_encode($c); ?> php.ini : serialize_precision =-1 sometimes it echo 0.2 ; sometimes it echo 0.1999999999999996 Test script: --------------- <?php $a=1.2; $b=1; $c=$a-$b; echo json_encode($c); ?> php.ini : serialize_precision =-1 sometimes it echo 0.2 ; sometimes it echo 0.1999999999999996 Expected result: ---------------- sometimes it echo 0.2 ; sometimes it echo 0.1999999999999996 Actual result: -------------- json_encode float error ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75254&edit=1

« previous php.bugs (#211351) next »