Bug #68111 [Opn->Nab]: json_decode introduces floating point precision error

From: Date: Mon, 29 Sep 2014 16:09:19 +0000
Subject: Bug #68111 [Opn->Nab]: json_decode introduces floating point precision error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187755@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68111&edit=1 ID: 68111 Updated by: aharvey@php.net Reported by: ryan at ryanparman dot com Summary: json_decode introduces floating point precision error -Status: Open +Status: Not a bug Type: Bug Package: JSON related Operating System: OS X PHP Version: 5.5.17 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. It's going to be the same value on both, just with different precision settings controlling the output. Previous Comments: ------------------------------------------------------------------------ [2014-09-27 05:05:07] ryan at ryanparman dot com This should be filed under JSON-related. ------------------------------------------------------------------------ [2014-09-27 05:00:56] ryan at ryanparman dot com Description: ------------ When decoding a JSON string with json_decode(), a floating point precision error gets introduced. Issue identified in PHP 5.5.17, and verified that it does NOT occur in 5.4.33. Test script: --------------- $data = json_decode('{"value": 4565.85}'); echo $data->value; Expected result: ---------------- I expected $data->value to have a value of 4565.85. Actual result: -------------- The actual value of $data->value is 4565.8500000000004. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68111&edit=1

« previous php.bugs (#187755) next »