RE: [PHP-WIN] Rounding
| From: | HKG) | Date: | Tue, 09 Apr 2002 15:49:26 +0000 |
| Subject: | RE: [PHP-WIN] Rounding | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12986@lists.php.net to get a copy of this message | ||
> Well, I suppose rounding by the dictionary's definition can mean any kind
> of approximation to a number of less significant digits, so I see your
> point.
To be a bit philosophical about it, yes. Rounding is always a matter of losing
information (e.g. precision), and you can never tell in what "direction" the
information was lost.
Ex:
The number '2' I now have, was it - to be extreme - it '1,1' (a sealing
function) or was it '2,9' (a floor function) before? You can never really
tell...
> But by the popular vernacular and by the default precision for any
> programming language's "round" function that I've encountered (including
> PHP's), the default precision is to round to the nearest integer.
Which integer is "nearest" for 1,5? 1 or 2? To round a decimal number is not
as straight forward as it might appear in the first case.
Anybody who happens to know what Kunts Handbook says in this issue?
> Thus, by
> both of these modest leaps of assumption, normal rounding to me is rounding
> to the nearest integer.
I agree that most rounding functions probably performs a sealing function
when the less significant decimal is >5 and a floor function when it is <5.
But what is a normal behavior when it is ==5 ???
In the bitter end this choice is up to the API writers own whim, but in most
case I guess (s)he ignore this case, and I would guess that most rounding
function then perform a floor function in the case of ==5 (????).
The point I want to make is this: You'll never know until you tested it!
Because of this I believe it a bit ambiguous to say "normal" since it hardly
can't exist a "normal" way to perform a rounding. Or??
Secondly, because of this "phenomena" some programmers might frequently find
them self having to answers question from customer like:
"Why does we miss $xxxx in this last summary report?".
> At 11:50 AM 4/9/2002 +0200, Svensson, B.A.T. (HKG) wrote:
> > > That will round down to 2 decimal places. To round to the nearest 2
> > > decimal places, to what Ross said but instead of getting the absolute
> > > value, just round it normally.
> >
> >What's "normal" rounding??????
>