note 7220 deleted from function.round by jeroen
| From: | jeroen@php.net | Date: | Sat, 01 Sep 2001 12:38:48 +0000 |
| Subject: | note 7220 deleted from function.round by jeroen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17498@lists.php.net to get a copy of this message | ||
Sorry, that was quite an oversight.. you obviously don't want to use ceil() unless you really
mean it. The proper fix is to round to one digit more than you need before adding the small
fraction:<br><br>(to get $places decimals)<br>function round_up($x,
$places)<br>round($x, $places + 1);<br>$x = $x + 1 / (pow(10, $places + 2)); // one
magnitude less than the first round<br>round($x, $places);<br>
return $x;
<br>}<br><br>(code not tested, YMMV)<br>Thats the general idea. Its a
little more code, but if you make it a function you may never even notice.