note 114573 added to function.round
| From: | takingsides at gmail dot com | Date: | Fri, 07 Mar 2014 15:00:23 +0000 |
| Subject: | note 114573 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198825@lists.php.net to get a copy of this message | ||
In my opinion this function lacks two flags:
- PHP_ROUND_UP - Always round up.
- PHP_ROUND_DOWN - Always round down.
In accounting, it's often necessary to always round up, or down to a precision of thousandths.
<?php
function round_up($number, $precision = 2)
{
$fig = (int) str_pad('1', $precision, '0');
return (ceil($number * $fig) / $fig);
}
function round_down($number, $precision = 2)
{
$fig = (int) str_pad('1', $precision, '0');
return (floor($number * $fig) / $fig);
}
?>
----
Server IP: 87.117.229.81
Probable Submitter: 62.232.70.247
----
Manual Page -- http://php.net/manual/en/function.round.php
Edit -- https://master.php.net/note/edit/114573
Del: integrated -- https://master.php.net/note/delete/114573/integrated
Del: useless -- https://master.php.net/note/delete/114573/useless
Del: bad code -- https://master.php.net/note/delete/114573/bad+code
Del: spam -- https://master.php.net/note/delete/114573/spam
Del: non-english -- https://master.php.net/note/delete/114573/non-english
Del: in docs -- https://master.php.net/note/delete/114573/in+docs
Del: other reasons-- https://master.php.net/note/delete/114573
Reject -- https://master.php.net/note/reject/114573
Search -- https://master.php.net/manage/user-notes.php