Re: ROUND function ??

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: ROUND function ??
Дата
Msg-id 21186.1002602561@sss.pgh.pa.us
обсуждение исходный текст
Ответ на ROUND function ??  ("Saurabh Mittal" <lattim@hotmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: SQL-Programmer tool and field%type support
Следующее
От: "Joe Conway"
Дата:
Сообщение: Re: ROUND function ??