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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 30 01:01:22 2020 UTC