note 100161 deleted from function.round by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Sep 2010 22:51:15 +0000 |
| Subject: | note 100161 deleted from function.round by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172791@lists.php.net to get a copy of this message | ||
Note Submitter: Matt
----
For lossantis, the results that you describe are not what PHP_HALF_ROUND_UP does. PHP_HALF_ROUND_UP
would round 6.3 to 6. In fact, all four $mode values would round 6.3 to 6. The function that you
want is ceil -- which rounds everything up. Note that your method has a bug: if you have exactly
6, you change to 6.5, which gets rounded up to 7.
The four mode values only control how .5 rounds. Anything less than .5 will round down always.
Anything more than .5 (e.g. .5001) rounds up always. If it is exactly .5, then the $mode values
matter. Note that if your precision is not the default 0, then this will be 5, .005, or something
else rather than .5.
PHP_HALF_ROUND_UP is the current behavior (versions prior to 5.3). The new behavior is that you can
choose to round differently in 5.3 (and presumably higher).