note 17884 added to function.round
| From: | felix at innovative-web dot NOSP dot AM dot de | Date: | Mon, 31 Dec 2001 11:07:04 +0000 |
| Subject: | note 17884 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24015@lists.php.net to get a copy of this message | ||
Hi!
Yet another update to the bcround function. Vittorio Moccia pointed out that it didn't work
with "infinite" precision. However, the function below allows you to gain the precision
you need. $precision specifies the number of decimals behind $decimals that shall be used for
rounding (10 or 20 is a good value). Hope this was the last bug in the function. If you find any
more, don't hesitate to contact me.
function bcround ($number, $decimals, $precision)
{
$precision_add = str_repeat("5",$precision);
if (bccomp($number,0) > 0)
{
return (bcadd (bcadd ($number, "0.".str_repeat("0",$decimals).$precision_add,
$decimals+$precision), 0, $decimals));
}
else
{
return (bcadd (bcsub ($number, "0.".str_repeat("0",$decimals).$precision_add,
$decimals+$precision), 0, $decimals));
}
}
- Felix Schwarz, Innovative
--
http://www.php.net/manual/en/function.round.php
http://master.php.net/manage/user-notes.php?action=edit+17884
http://master.php.net/manage/user-notes.php?action=delete+17884
http://master.php.net/manage/user-notes.php?action=reject+17884