note 101398 deleted from ref.bc by danbrown

From: Date: Tue, 14 Dec 2010 22:14:19 +0000
Subject: note 101398 deleted from ref.bc by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174923@lists.php.net to get a copy of this message
Note Submitter: coops ---- The rounding function below by Charles is invalid (as it does not round negative numbers correctly) and it does unnecessary/wrong input checking that does not work with some input. This function is simple and rounds both negative and positive numbers: <?php /** * Rounds number to specified precision. * @param string $number * @param integer $precision * @see http://www.nanomvc.com/ * @return string */ public static function bcRound($number, $precision) { return \bcadd($number, (\bccomp($number, "0") == -1? "-": "") . "0." . \str_repeat("0", $precision) . "5", $precision); } ?>

« previous php.notes (#174923) next »