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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
13 - 3 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 10:01:29 2024 UTC