|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-12-14 14:07 UTC] chenjiablog at gmail dot com
Description:
------------
When using this function to deal with an array containing decimal, there will be precision problems.
Test script:
---------------
<?php
$array['a'] = "as";
$array['b'] = 1;
$array['c'] = 1.13;
$array['d'] = 10.08;
echo json_encode($array);
Expected result:
----------------
{"a":"as","b":1,"c":1.13,"d":10.08}
Actual result:
--------------
{"a":"as","b":1,"c":1.1299999999999999,"d":10.08}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 20:00:01 2025 UTC |
jhdxr@php.net, I confirm that this problem exists and reproduced both in 7.1.0 and 7.1.1. About your example I think it can be specific behaviour on 3v4l.org. To reproduce issue you can try it from CLI for example: # cat test.php <?php $array['a'] = "as"; $array['b'] = 1; $array['c'] = 1.13; $array['d'] = 10.08; echo json_encode($array); # php -v PHP 7.1.1 (cli) (built: Jan 18 2017 11:37:34) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.1.1, Copyright (c) 1999-2017, by Zend Technologies # php test.php {"a":"as","b":1,"c":1.1299999999999999,"d":10.08}