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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: renan dot nannetti at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 11:01:27 2024 UTC