note 73537 modified in function.round by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:18:55 +0000 |
| Subject: | note 73537 modified in function.round by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154794@lists.php.net to get a copy of this message | ||
The function round numbers to a given precision.
<?php
function toFixed($number, $round=2)
{
$tempd = $number*pow(10,$round);
$tempd1 = round($tempd);
$number = $tempd1/pow(10,$round);
return $number;
}
echo round(5.555,2); //retunr 5.55 - I don't know why
echo toFixed(5.555,2); //return 5.56
?>
--was--
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 round(5.555,2); //retunr 5.55 - I don\t know why
echo toFixed(5.555,2); //return 5.56
http://php.net/manual/en/function.round.php