RE: [PHP] round()

From: Date: Wed, 10 Oct 2007 22:18:36 +0000
Subject: RE: [PHP] round()
Groups: php.general 
Request: Send a blank email to php-general+get-263066@lists.php.net to get a copy of this message
> While we're entertaining algorithms, has anyone else noticed that > php's round() isn't the most accurate algorithm to round? If you will refer to chafy's reply on 28-Feb-2007 06:13 <http://us2.php.net/manual/en/function.round.php#73537> The function round numbers to a given precision. function toFixed($number, $round=2) { $tempd = $number*pow(10,$round); $tempd1 = round($tempd); $number = $tempd1/pow(10,$round); return $number; } echo toFixed(5.555,2); //return 5.56 If your rounding issue is passed 2 decimal places. I found this function covenant and problem solving. As for the accuracy of the algorithm I disagree. I will need to see an example where the round() is inaccurate.

« previous php.general (#263066) next »