Re: ROUND function ??

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Saurabh Mittal" <lattim(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ROUND function ??
Date: 2001-10-09 04:42:41
Message-ID: 21186.1002602561@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Saurabh Mittal" <lattim(at)hotmail(dot)com> writes:
> select ROUND(0.5) ; returns 0
> select ROUND(1.5) ; returns 2;
> select ROUND(2.5) ; returns 2;
> select ROUND(3.5) ; returns 4;....so on .=20
> I'm sure you would have figured out what's happening !!! Why ??

Because the IEEE float math standard says so. Round-to-nearest-even
is considered good practice.

> How do I get to approximate any number x.5 as x+1 ??

Try FLOOR(x + 0.5) if you really want the other behavior.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Joe Conway 2001-10-09 05:03:50 Re: ROUND function ??
Previous Message Tom Lane 2001-10-09 04:34:07 Re: SQL-Programmer tool and field%type support