Bug #68200 [NEW]: json_decode rounding floats to 3 digits precision

From: Date: Thu, 09 Oct 2014 14:00:19 +0000
Subject: Bug #68200 [NEW]: json_decode rounding floats to 3 digits precision
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187986@lists.php.net to get a copy of this message
From:             vwirus at o2 dot pl
Operating system: linux/debian
PHP version:      5.5.17
Package:          JSON related
Bug Type:         Bug
Bug description:json_decode rounding floats to 3 digits precision

Description:
------------
json_decode rounding floats to 3 digits precision. My precision setting
in php.ini shows 14.


Test script:
---------------
$tmp = json_decode('{"number":1000000.66599998}', true);
        if (false !== strpos((string) $tmp['number'], '1000000.666')) {
            echo PHP_EOL, 'WRONG', PHP_EOL;
        }
        else {
            echo PHP_EOL, 'OK', PHP_EOL;
        }
        var_dump($tmp, $tmp['number']);

Expected result:
----------------
After decode the value of $tmp['number'] should be 1000000.66599998.

Actual result:
--------------
After decode the value of $tmp['number'] shows be 1000000.666 (it rounds
real value with 3 digits precision)

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



Thread (8 messages)

« previous php.bugs (#187986) next »