RE: round()

From: Date: Thu, 11 Oct 2007 18:26:06 +0000
Subject: RE: round()
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-263113@lists.php.net to get a copy of this message
I get correct results: 5.2.4 PHP_VERSION round(5.555,2):5.56 toFixed(5.555,2):5.56 admin-214 wrote: > >> 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. > > > > > -- View this message in context: http://www.nabble.com/round%28%29-tf4602528.html#a13161858 Sent from the PHP - General mailing list archive at Nabble.com.

« previous php.general (#263113) next »