php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77197 rounding problem
Submitted: 2018-11-25 13:00 UTC Modified: 2018-11-30 15:54 UTC
From: php_bug at sport-sachsenhausen dot de Assigned:
Status: No Feedback Package: *Math Functions
PHP Version: 7.2.12 OS: Linux
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: php_bug at sport-sachsenhausen dot de
New email:
PHP Version: OS:

 

 [2018-11-25 13:00 UTC] php_bug at sport-sachsenhausen dot de
Description:
------------
rounding function not as expected

Test script:
---------------
#  tested PHP 5.2, 5.3, 5.4, 5.5, 5.6, 7.0, 7.2.12
for( $i = 0; $i < 100; $i += 0.001 ) {
	$r_0	= round( $i );
	$r_up	= round( $i, 2, PHP_ROUND_HALF_UP );
	$r_down	= round( $i, 2, PHP_ROUND_HALF_DOWN );
	# a) missing values 
	#	Line  7- 8:  0,085 +  0,095
	#	Line 73-74:  0,765 -  0,995
	#	Line 78-79:  1,055 -  4,965
	#	Line 81-82:  5,005 -  9,795
	#	Line 83-84:  9,825 - 18,755
	#	Line 92-93: 18,855 - 38,885
	#	Line 97-98: 38,945 - 76,225
	#	Line 101+ : 76,235 - 99,995
	if( $r_up == $r_down ) continue; // comment out... -> attention! producing 99.999 lines
	#	see lines: 1.461 - 4.836, 5.137 - 9.723, 9.905 - 10.000, 10.717 - 18.396,
	#	19.215 - 38.703, 39.133 - 76.139, 76.349 - 99.999
	echo 'Line ' . $count++ . "| {$i} | round 0: {$r_0} | half up: {$r_up} | half down: {$r_down} <br>";
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-25 14:00 UTC] peehaa@php.net
-Status: Open +Status: Feedback
 [2018-11-25 14:00 UTC] peehaa@php.net
It's not clear what this report is about.

Please provide a clear explanation about what in specific is not working "as expected", with:

- a simple reproduce case
- the expected result
- the actual result
 [2018-11-30 15:54 UTC] peehaa@php.net
-Status: Feedback +Status: No Feedback
 [2018-11-30 15:54 UTC] peehaa@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 06:01:28 2024 UTC