note 84809 added to function.round
| From: | chris at chrisstockton dot org | Date: | Wed, 30 Jul 2008 23:05:01 +0000 |
| Subject: | note 84809 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142963@lists.php.net to get a copy of this message | ||
In case anyone has a problem like me ever, were you are doing very large stat calculations on a
array and end up with floats with way to large of precision. A good way to round them all to N
length is below.
public function recursiveRound(array &$arr, $precision)
{
foreach($arr as $key => $val) {
if(is_array($val)) {
$this->recursiveRound($arr[$key], $precision);
} elseif(is_float($val)) {
$arr[$key] = round($arr[$key], $precision);
}
}
return $arr;
}
----
Server IP: 209.41.74.194
Probable Submitter: 64.202.160.65
----
Manual Page -- http://www.php.net/manual/en/function.round.php
Edit -- https://master.php.net/note/edit/84809
Del: integrated -- https://master.php.net/note/delete/84809/integrated
Del: useless -- https://master.php.net/note/delete/84809/useless
Del: bad code -- https://master.php.net/note/delete/84809/bad+code
Del: spam -- https://master.php.net/note/delete/84809/spam
Del: non-english -- https://master.php.net/note/delete/84809/non-english
Del: in docs -- https://master.php.net/note/delete/84809/in+docs
Del: other reasons-- https://master.php.net/note/delete/84809
Reject -- https://master.php.net/note/reject/84809
Search -- https://master.php.net/manage/user-notes.php