Bug #78172 [Opn]: Wrong rounding up/down when decimal places are specified
| From: | danack@php.net | Date: | Sun, 16 Jun 2019 17:00:41 +0000 |
| Subject: | Bug #78172 [Opn]: Wrong rounding up/down when decimal places are specified | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221336@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: danack@php.net
Reported by: vecera at zdenekvecera dot cz
Summary: Wrong rounding up/down when decimal places are
specified
Status: Open
Type: Bug
Package: *Math Functions
Operating System: Windows, Linux
PHP Version: 7.1.30
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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