note 78414 deleted from function.round by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:17:07 +0000 |
| Subject: | note 78414 deleted from function.round by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154785@lists.php.net to get a copy of this message | ||
Note Submitter: thawee from thailand
----
my round function
function rounding($n,$d){
$base=intval($n);
$n=number_format($n,25);
$dotpos=strpos($n,".");
$strlen=strlen($n);
$b= substr($n,$dotpos+1,$strlen-$dotpos);
$j=1;
$p=0;
for($i=strlen($b);$i>$d;$i--){
$c=substr($b,-$j,1)+$p;
if($c<5){
$p=0;
}else{
$p=1;
}
$j++;
}
return $base+((substr($b,0,$d)+$p)/pow(10,$d));
}