From: Lee Hachadoorian <lee.hachadoorian@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Round integer division
Date: Fri, 25 Jun 2010 18:53:01 -0400
Message-ID: <4C25334D.4040805@gmail.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: lee.hachadoorian@gmail.com
Subject: Re: Round integer division
In-Reply-To: <4C25334D.4040805@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox