Re: Round() behaviour issue
| From: | Eugene Lee | Date: | Tue, 16 Dec 2003 12:39:58 +0000 |
| Subject: | Re: Round() behaviour issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-172795@lists.php.net to get a copy of this message | ||
On Tue, Dec 16, 2003 at 11:13:25AM +0000, Scott McDaid wrote:
:
: Hi there. I've been looking at the behaviour of the round functionality in
: PHP. We're currently still using v4.2.3, (but the documentation seems to
: suggest it's the same for versions after this).
:
: Doing the following rounds always rounds *up* to the nearest whole number.
: i.e.
:
: 0.5 => 1
: 1.5 => 2
: 2.5 => 3
: 3.5 => 4
Any non-zero fractional component that gets rounded to the next whole
number is done with ceil().
: In earlier PHP docs, it stated that halves would be rounded to the nearest
: even number.
: i.e.
:
: 3.5 => 4
: 4.5 => 4
I recall seeing those docs and getting very confused, especially with
your listed example. Personally, I think the current behavior for
round() is mathematically correct; i.e. any number whose fractional
component is greater-than or equal-to 1/2 is rounded up to the next
whole number, otherwise it's rounded down.