note 85084 modified in ref.bc by felipe
| From: | felipe@php.net | Date: | Fri, 15 Aug 2008 03:32:17 +0000 |
| Subject: | note 85084 modified in ref.bc by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143514@lists.php.net to get a copy of this message | ||
Function to round bc string:
<?php
function bcround($strval, $precision = 0) {
if (false !== ($pos = strpos($strval, '.')) && (strlen($strval) - $pos - 1) >
$precision) {
$zeros = str_repeat("0", $precision);
return bcadd($strval, "0.{$zeros}5", $precision);
} else {
return $strval;
}
}
?>
--was--
Function to round bc string:
function bcround($strval, $precision = 0) {
if (false !== ($pos = strpos($strval, '.')) && (strlen($strval) - $pos - 1) >
$precision) {
$zeros = str_repeat("0", $precision);
return bcadd($strval, "0.{$zeros}5", $precision);
} else {
return $strval;
}
}
http://php.net/manual/en/ref.bc.php