note 76912 deleted from function.round by danbrown

From: Date: Sun, 17 May 2009 16:17:50 +0000
Subject: note 76912 deleted from function.round by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154789@lists.php.net to get a copy of this message
Note Submitter: Pascal Hofmann ---- 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)); } }

« previous php.notes (#154789) next »