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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC