Bug #75700 [Opn->Nab]: Incorrect number after json_encode
| From: | nikic@php.net | Date: | Wed, 20 Dec 2017 20:34:24 +0000 |
| Subject: | Bug #75700 [Opn->Nab]: Incorrect number after json_encode | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213193@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75700&edit=1
ID: 75700
Updated by: nikic@php.net
Reported by: admin at twister-vl dot ru
Summary: Incorrect number after json_encode
-Status: Open
+Status: Not a bug
Type: Bug
Package: JSON related
Operating System: All
PHP Version: 7.2.0
Block user comment: N
Private report: N
New Comment:
The actual result is correct, please see https://3v4l.org/BfqFu.
If you'd like to receive the old result (though you should ask yourself why you want that) you
can either
a) change the serialize_precision setting, understanding that you will no longer receive an accurate
floating-point representation, or
b) explicitly round your floating point numbers to a lower level of precision.
Previous Comments:
------------------------------------------------------------------------
[2017-12-17 18:30:38] admin at twister-vl dot ru
Description:
------------
Some numbers after json_encode may contain unexpected zeros.
Test script:
---------------
<?php
$a = (1010*(0.00003*100))/100;
echo $a;
echo "\n";
echo json_encode($a);
Expected result:
----------------
0.0303
0.0303
Actual result:
--------------
0.0303
0.030300000000000004
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75700&edit=1