RE: round()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux