note 17884 deleted from function.round by bobby
| From: | bobby@php.net | Date: | Mon, 06 Aug 2007 14:24:58 +0000 |
| Subject: | note 17884 deleted from function.round by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129205@lists.php.net to get a copy of this message | ||
Note Submitter: felix at innovative-web dot NOSP dot AM dot de
----
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