php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36310 floor() and ceil() to take precision argument
Submitted: 2006-02-07 02:05 UTC Modified: 2010-11-19 01:10 UTC
Votes:3
Avg. Score:4.0 ± 1.4
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: daedalon at users dot sourceforge dot net Assigned: jani (profile)
Status: Closed Package: Math related
PHP Version: 5.1.2 OS: any
Private report: No CVE-ID: None
 [2006-02-07 02:05 UTC] daedalon at users dot sourceforge dot net
Description:
------------
Since PHP 4, round() takes precision as a parameter. This would be very useful for floor() and ceil() too for there are cases when one wants to round fractions up or down to certain precision.


By the way the documentation for floor() and ceil() could make a note of how the functions act for zero decimals to increase clarity. Currently the behavior could be too easily misinterpreted by someone non-native English reader.

Reproduce code:
---------------
echo round(5.055, 2);  // Prints 5.06 as expected
echo floor(15.075, 2); // Should print 15,07 but prints 15
echo ceil(3.041, 2);   // Should print 3,05 but prints 4

Expected result:
----------------
echo round(5.055, 2);  // Prints 5.06 as expected
echo floor(15.075, 2); // Should print 15,07 but prints 15
echo ceil(3.041, 2);   // Should print 3,05 but prints 4

Actual result:
--------------
echo round(5.055, 2);  // Prints 5.06 as expected
echo floor(15.075, 2); // Should print 15,07 but prints 15
echo ceil(3.041, 2);   // Should print 3,05 but prints 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-07 08:26 UTC] derick@php.net
Marking as Feature Request.
 [2010-11-19 01:10 UTC] jani@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: Math related -Assigned To: +Assigned To: jani
 [2010-11-19 01:10 UTC] jani@php.net
Same as bug #23498
 [2010-11-19 01:10 UTC] jani@php.net
-Block user comment: N +Block user comment: Y
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Nov 26 23:05:53 2022 UTC