Bug #68200 [Com]: json_decode rounding floats to 3 digits precision
Edit report at https://bugs.php.net/bug.php?id=68200&edit=1
ID: 68200
Comment by: marcin at urzenia dot net
Reported by: vwirus at o2 dot pl
Summary: json_decode rounding floats to 3 digits precision
Status: Open
Type: Bug
Package: JSON related
Operating System: linux/debian
PHP Version: 5.5.17
Block user comment: N
Private report: N
New Comment:
It's float problem, not JSON:
var_dump((float)"1000000.66599998") => float(1000000.666)
Previous Comments:
------------------------------------------------------------------------
[2014-10-09 14:00:18] vwirus at o2 dot pl
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 this bug report at https://bugs.php.net/bug.php?id=68200&edit=1
Thread (8 messages)