Re: round(50.5) = 50

Поиск
Список
Период
Сортировка
От Chris Browne
Тема Re: round(50.5) = 50
Дата
Msg-id 60y8qkob0s.fsf@dev6.int.libertyrms.info
обсуждение исходный текст
Ответ на round(50.5) = 50  (Philipp Matthias Hahn <Philipp.Hahn@informatik.uni-oldenburg.de>)
Список pgsql-bugs
Philipp.Hahn@informatik.uni-oldenburg.de (Philipp Matthias Hahn) writes:
> # SELECT round(5.5::float4),round(50.5::float4);
>   round | round
> -------+-------
>       6 |    50
> (1 row)
>
> I think this is a bug, since I would expect 6 and 51. Doing the same
> without the float4-cast, it works correct. This bug bites me while
> passing parameters to a plpgsql function.
>
> This happens both with Debian 7.3.4-9 and 7.4.1-3
>
> Is this a real bug or am I missing something? A bug fix or work-around
> would be nice.

Why would this be a bug?

A common policy for rounding is "round to even."  That has the merit
of not being biased whether you're working with positive or negative
values.

It looks as though your LIBC is using "round-to-even."
--
(reverse (concatenate 'string "gro.mca" "@" "enworbbc"))
http://cbbrowne.com/info/sap.html
"For those  of you who are  into writing programs that  are as obscure
and complicated  as possible, there are opportunities  for... real fun
here" -- Arthur Norman

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Philipp Matthias Hahn
Дата:
Сообщение: Re: round(50.5) = 50
Следующее
От: margitsw@t-online.de (Margit Schubert-While)
Дата:
Сообщение: Re: ecpg segmentation error