Bug #78172 [Opn->Nab]: Wrong rounding up/down when decimal places are specified
| From: | cmb@php.net | Date: | Sun, 16 Jun 2019 17:04:01 +0000 |
| Subject: | Bug #78172 [Opn->Nab]: Wrong rounding up/down when decimal places are specified | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221337@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78172&edit=1
ID: 78172
Updated by: cmb@php.net
Reported by: vecera at zdenekvecera dot cz
Summary: Wrong rounding up/down when decimal places are
specified
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: Windows, Linux
PHP Version: 7.1.30
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
It's like @danack said; IOW the PHP_ROUND_HALF_* constants are
only relevant when the fractional part of $val * 10**$precision is
exactly 0.5.
Previous Comments:
------------------------------------------------------------------------
[2019-06-16 17:00:41] danack@php.net
I don't understand what how you get your expected values.
// round(1.44444, 3, PHP_ROUND_HALF_UP) (correct value: 1.445)
That would be the same as expected 0.00044 rounded to 3 digits to be 0.001. but 0.00044 is less than
0.0005 which is the halfway point to 0.001.
Similarly 0.00055 rounded to 3 figures is going to be 0.001 no matter the rounding.
------------------------------------------------------------------------
[2019-06-16 16:18:00] vecera at zdenekvecera dot cz
Description:
------------
var_dump(round(1.44444, 3, PHP_ROUND_HALF_DOWN)); // float(1.444) OK
var_dump(round(1.55555, 3, PHP_ROUND_HALF_DOWN)); // float(1.556) BUG (correct value: 1.555)
var_dump(round(1.77777, 3, PHP_ROUND_HALF_DOWN)); // float(1.778) BUG (correct value: 1.777)
var_dump(round(1.44444, 3, PHP_ROUND_HALF_UP)); // float(1.444) BUG (correct value: 1.445)
var_dump(round(1.55555, 3, PHP_ROUND_HALF_UP)); // float(1.556) OK
var_dump(round(1.77777, 3, PHP_ROUND_HALF_UP)); // float(1.778) OK
// PHP version: 7.0.33, 7.1.30, 7.2.19, 7.3.6
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78172&edit=1