Bug #68111 [NEW]: json_decode introduces floating point precision error

From: Date: Sat, 27 Sep 2014 05:00:57 +0000
Subject: Bug #68111 [NEW]: json_decode introduces floating point precision error
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187730@lists.php.net to get a copy of this message
From:             ryan at ryanparman dot com
Operating system: OS X
PHP version:      5.5.17
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:json_decode introduces floating point precision error

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 bug report at https://bugs.php.net/bug.php?id=68111&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68111&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68111&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68111&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68111&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68111&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68111&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68111&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68111&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68111&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68111&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68111&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68111&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68111&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68111&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68111&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68111&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68111&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68111&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68111&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68111&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#187730) next »