Re: Round integer division

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: Lee Hachadoorian <lee(dot)hachadoorian(at)gmail(dot)com>
Subject: Re: Round integer division
Date: 2010-06-25 23:25:48
Message-ID: 201006251625.48231.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Friday 25 June 2010 3:53:01 pm Lee Hachadoorian 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?
>
> Thanks,
>
> --
>
> Lee Hachadoorian
> PhD Student, Geography
> Program in Earth & Environmental Sciences
> CUNY Graduate Center

See here for explanation:
http://archives.postgresql.org/pgsql-general/2010-03/msg00969.php

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Osvaldo Kussama 2010-06-25 23:28:58 Re: How do I remove selected words from text field?
Previous Message Lee Hachadoorian 2010-06-25 23:07:40 Re: Round integer division