php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75690 PHP 7.1 changes precision when using json_encode() to encode floats
Submitted: 2017-12-14 19:13 UTC Modified: 2017-12-14 21:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: renan dot nannetti at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 7.1.12 OS: RHEL6
Private report: No CVE-ID: None
 [2017-12-14 19:13 UTC] renan dot nannetti at gmail dot com
Description:
------------
Description:
------------
json_encode() is presenting rounding issues when trying to encode float values.

Note: I'm using serialize_precision equals to -1 in my php.ini.


Test script:
---------------
<?php
echo json_encode((floatval(-0.717655) - floatval(6.7173)));

Expected result:
----------------
'-7.434955'

Actual result:
--------------
'-7.4349549999999995'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-14 21:05 UTC] yohgaki@php.net
-Status: Open +Status: Not a bug
 [2017-12-14 21:05 UTC] yohgaki@php.net
From PHP 7.1, precision handling differ. I suppose it's in UPGRADING.
Use "valid" serialize_precision if you need specific precision.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 23:01:24 2019 UTC