note 49893 deleted from function.round by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:23:12 +0000 |
| Subject: | note 49893 deleted from function.round by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154814@lists.php.net to get a copy of this message | ||
Note Submitter: ron at korving dot demon dot nl
----
Unfortunately, ranzoategui's (and my revision) round version did not work well (try to round
8.075 to 2 decimals for example).
I found out the best way to achieve a good round is to add a tiny number to the value before
rounding. This seems to work fine in all cases (and luckily it's faster than previous methods):
<?
function stdround($num, $d=0)
{
return round($num + 0.0001 / pow(10, $d), $d);
}
?>