Re: ROUND function ?? - Mailing list pgsql-sql

From Tom Lane
Subject Re: ROUND function ??
Date
Msg-id 21186.1002602561@sss.pgh.pa.us
Whole thread Raw
In response to ROUND function ??  ("Saurabh Mittal" <lattim@hotmail.com>)
List pgsql-sql
"Saurabh Mittal" <lattim@hotmail.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: SQL-Programmer tool and field%type support
Next
From: "Joe Conway"
Date:
Subject: Re: ROUND function ??