note 76912 added to function.round
| From: | PascalHofmann at osu1 dot php dot net | Date: | Sun, 05 Aug 2007 06:21:29 +0000 |
| Subject: | note 76912 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129184@lists.php.net to get a copy of this message | ||
The function from Felix Schwarz returns wrong results for values near 0. bccomp should be called
with param $scale.
function bcround ($number, $decimals, $precision) {
$precision_add = str_repeat("5",$precision);
if (bccomp($number,0, $decimals+$precision) > 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));
}
}
----
Server IP: 217.160.72.57
Probable Submitter: 85.180.139.102
----
Manual Page -- http://www.php.net/manual/en/function.round.php
Edit -- https://master.php.net/note/edit/76912
Del: integrated -- https://master.php.net/note/delete/76912/integrated
Del: useless -- https://master.php.net/note/delete/76912/useless
Del: bad code -- https://master.php.net/note/delete/76912/bad+code
Del: spam -- https://master.php.net/note/delete/76912/spam
Del: non-english -- https://master.php.net/note/delete/76912/non-english
Del: in docs -- https://master.php.net/note/delete/76912/in+docs
Del: other reasons-- https://master.php.net/note/delete/76912
Reject -- https://master.php.net/note/reject/76912
Search -- https://master.php.net/manage/user-notes.php