|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78172 Wrong rounding up/down when decimal places are specified
Submitted: 2019-06-16 16:18 UTC Modified: 2019-06-16 17:04 UTC
From: vecera at zdenekvecera dot cz Assigned: cmb (profile)
Status: Not a bug Package: *Math Functions
PHP Version: 7.1.30 OS: Windows, Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: vecera at zdenekvecera dot cz
New email:
PHP Version: OS:


 [2019-06-16 16:18 UTC] vecera at zdenekvecera dot cz
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-16 17:00 UTC]
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 17:04 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2019-06-16 17:04 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 16:01:29 2024 UTC