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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 04:01:29 2024 UTC