php.net |  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
Votes:6
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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.
Example
it is not easy to round $24.203 to $24.21

Thanks

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] jani@php.net
-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] ajf@php.net
-Status: Open +Status: Wont fix
 [2015-01-08 22:31 UTC] ajf@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Sun Nov 17 03:01:36 2019 UTC