note 49893 added to function.round

From: Date: Fri, 11 Feb 2005 10:46:17 +0000
Subject: note 49893 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-84843@lists.php.net to get a copy of this message
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); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49893 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49893&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49893&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49893&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49893&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49893&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49893&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84843) next »