|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23498 ceil() / floor() needs precision option
Submitted: 2003-05-05 18:45 UTC Modified: 2015-01-08 22:31 UTC
Avg. Score:3.5 ± 1.0
Reproduced:4 of 5 (80.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: junk at factory8 dot com Assigned:
Status: Wont fix Package: Math related
PHP Version: * OS: *
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.
Block user comment
Status: Assign to:
Bug Type:
From: junk at factory8 dot com
New email:
PHP Version: OS:


 [2003-05-05 18:45 UTC] junk at factory8 dot com
ceil() should have a percision option. This would greatly help in rounding for tax.
it is not easy to round $24.203 to $24.21



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-06 11:44 UTC] michael dot mauch at gmx dot de
$x = 24.203;
echo ceil($x*100)/100,"\n";

Would it be good enough if the manual would hint into that direction?
 [2010-11-19 01:08 UTC]
-Summary: ceil() needs more options +Summary: ceil() / floor() needs precision option -Package: Feature/Change Request +Package: Math related -PHP Version: 4.3.2RC2 +PHP Version: *
 [2013-04-19 11:28 UTC] phpmpan at mpan dot pl
In the context of bug 64675 and bug 64674 I dig up a 10 years old bug.

Both `ceil` and `floor` functions make no sense for floating point numbers except a small subset of them. This is because either:
 - There is no element in the floating point numbers set that matches the result of these functions.
 - A relative difference between the result and the input is so small that it's irrelevant.

As per original report: floating point numbers should NEVER be used for financial calculations.
 [2015-01-08 22:31 UTC]
-Status: Open +Status: Wont fix
 [2015-01-08 22:31 UTC]
As michael points out, you can do /100 and *100.

Also, yes, don't do tax.

This probably won't be added.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 13:01:32 2024 UTC