Re: Round integer division

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Lee Hachadoorian <lee(dot)hachadoorian(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Round integer division
Date: 2010-06-25 23:00:40
Message-ID: AANLkTinq3e-fl89_zIdEShmhK2KnUUpZZjUAYhHVnWqr@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Jun 25, 2010 at 6:53 PM, Lee Hachadoorian
<lee(dot)hachadoorian(at)gmail(dot)com> wrote:
> Is it documented anywhere that floating-point numbers round
> "scientifically", that is 0.5 rounds to the nearest even number? Compare:
>
> SELECT round(2.5::real), round(2.5::numeric), round(3.5::real),
> round(3.5::numeric);
>
> generates
>
> 2 | 3 | 4 | 4
>
> I stumbled across this when I was trying to use round(a::real/b::real)
> to generate a rounded result to dividing integers, and noticed sometimes
> 0.5 was truncated and sometimes it was rounded up. Couldn't find
> anything about this in the archives or the data type documentation. Is
> there something obvious that I'm I missing?

That all floating point representations are approximate?

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Lee Hachadoorian 2010-06-25 23:07:40 Re: Round integer division
Previous Message Lee Hachadoorian 2010-06-25 22:53:01 Round integer division