Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version
| От | Pedro Gimeno |
|---|---|
| Тема | Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version |
| Дата | |
| Msg-id | 55159907.1060809@personal.formauri.es обсуждение исходный текст |
| Ответ на | Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version (Michael Paquier <michael.paquier@gmail.com>) |
| Список | pgsql-bugs |
Michael Paquier wrote, On 2015-03-27 13:32:
> Attached is a patch that adds nearest-to-even rounding for numeric
> when dscale = 0. This gives the following results with the previous
> query:
That produces some quite surprising results:
=# select '2.5'::numeric(9,0)::numeric(9,1),
'2.25'::numeric(9,1)::numeric(9,2),
'2.225'::numeric(9,2)::numeric(9,3),
'2.2225'::numeric(9,3)::numeric(9,4),
'2.22225'::numeric(9,4)::numeric(9,5);
numeric | numeric | numeric | numeric | numeric
---------+---------+---------+---------+---------
2.0 | 2.30 | 2.230 | 2.2230 | 2.22220
(1 row)
That rounding is inconsistent: since DEC_DIGITS is 4 by default, numbers
with a number of digits which is a multiple of 4 + 1 will be rounded to
nearest or even, and numbers with a different number of digits will be
rounded up on a tie. And I have not tested, but apparently when
DEC_DIGITS == 1 (array elements are single digits rather than packing
several) it always rounds down on a tie.
В списке pgsql-bugs по дате отправления: