php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70316 round function bug
Submitted: 2015-08-21 05:32 UTC Modified: 2015-08-21 09:20 UTC
From: 277460173 at qq dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.4Git-2015-08-21 (Git) OS: linux nginx PHP/5.4.41
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 277460173 at qq dot com
New email:
PHP Version: OS:

 

 [2015-08-21 05:32 UTC] 277460173 at qq dot com
Description:
------------
$source=1370.72;
$local=1238.265;
$aa=($source - $local) / $source;
dump($aa);
$bb=  round($aa,4);
dump($bb);
dump(phpversion());

result:

float(0.09663169721022523)

float(0.09660000000000001)

string(6) "5.4.41"

Test script:
---------------
$source=1370.72;
$local=1238.265;
$aa=($source - $local) / $source;
dump($aa);
$bb=  round($aa,4);
dump($bb);
dump(phpversion());




Expected result:
----------------
float(0.09663169721022523)

float(0.0966)

string(6) "5.4.41"

Actual result:
--------------
float(0.09663169721022523)

float(0.09660000000000001)

string(6) "5.4.41"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-21 07:18 UTC] laruence@php.net
what's the "dump" function's definition ?
 [2015-08-21 07:19 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2015-08-21 08:03 UTC] yohgaki@php.net
This isn't a bug, but a spec that dumps internal data directly.

Anyway, I'm preparing patch that actually rounds float when precision=-1. export() rounds value to the nearest. What should we do for dump?
 [2015-08-21 08:04 UTC] yohgaki@php.net
s/export()/var_export()/
 [2015-08-21 09:19 UTC] 277460173 at qq dot com
-Status: Feedback +Status: Closed
 [2015-08-21 09:19 UTC] 277460173 at qq dot com
ini_set('precision', 14);
 [2015-08-21 09:20 UTC] 277460173 at qq dot com
ini_set('precision', 14);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 18:01:28 2024 UTC