List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:September 28 1999 3:04pm
Subject:Re: Weird ROUND behaviour
View as plain text  
On Mon, 1999-09-27 08:40:30 -0500, Paul DuBois wrote:
> At 8:32 AM -0500 9/27/99, Juho Tikkala wrote:
> >Why doesn't the ROUND function work like it says in the manual? The manual
> >says:
> >
> >mysql> select ROUND(-1.58);
> >        -> -2
> >mysql> select ROUND(1.298, 0);
> >        -> 1
> >
> >But the reality is something like this:
[...]
> >+--------------+
> >| ROUND(-1.58) |
> >+--------------+
> >|           -1 |
> >+--------------+
[...]
> >+-----------------+
> >| ROUND(1.298, 0) |
> >+-----------------+
> >|               2 |
> >+-----------------+
[...]
> 
> ROUND() depends on the behavior of the underlying system call.
> Apparently that call behaves differently under Windows than under
> the UNIX system used to generate the examples in the manual.
> (The behavior probably varies among versions of UNIX as well.)

Though this might be the explanation of the different results, I
clearly see this as a bug!

In my opinion, MySQL should ensure a well-defined behaviour of ROUND()
regardless of the underlying system!

The expected behaviour for ROUND(), as I see it, would be to round
toward the nearest integer number:
  ROUND(-1.9) --> -2
  ROUND(-1.1) --> -1
  ROUND(0.1)  -->  1
  ROUND(0.9)  -->  2

For ".5"-numbers it's probably best to have an option whether these
numbers-in-the-middle
- should always by rounded up towards the next greater integer,
    ROUND(-2.5) --> -2
    ROUND(-1.5) --> -1
    ROUND(-0.5) -->  0
    ROUND( 0.5) -->  1
    ROUND( 1.5) -->  2
    ROUND( 2.5) -->  3
- or should be rounded towards the next even integer,
    ROUND(-2.5) --> -2
    ROUND(-1.5) --> -2
    ROUND(-0.5) -->  0
    ROUND( 0.5) -->  0
    ROUND( 1.5) -->  2
    ROUND( 2.5) -->  2
Both methods have their raison d'être ...

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
Weird ROUND behaviourJuho Tikkala27 Sep
  • Re: Weird ROUND behaviourPaul DuBois27 Sep
    • Re: Weird ROUND behaviourMartin Ramsch28 Sep
      • Re: Weird ROUND behaviourThimble Smith28 Sep
  • Re: Weird ROUND behaviourSteve Ruby28 Sep
    • Re: Weird ROUND behaviourMartin Ramsch28 Sep
    • Re: Weird ROUND behaviourMichael Widenius29 Sep
      • Re: Weird ROUND behaviourBob Kline29 Sep
        • Re: Weird ROUND behaviourTonu Samuel29 Sep
          • Re: Weird ROUND behaviourJames Manning29 Sep
        • Re: Weird ROUND behaviourScott Hess29 Sep
        • Re: Weird ROUND behaviourTonu Samuel30 Sep
        • Re: Weird ROUND behaviourScott Hess30 Sep
        • Re: Weird ROUND behaviourTonu Samuel30 Sep