Re: BUG #6217: to_char() gives incorrect output for very small float values

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #6217: to_char() gives incorrect output for very small float values
Дата
Msg-id 11125.1316540968@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #6217: to_char() gives incorrect output for very small float values  ("Chris Gernon" <kabigon@gmail.com>)
Список pgsql-bugs
"Chris Gernon" <kabigon@gmail.com> writes:
> CREATE TABLE t (
> id serial,
> f double precision,
> CONSTRAINT t_pk PRIMARY KEY (id)
> );

> INSERT INTO t (f) VALUES (0.0000000000000000000000000000000563219288);

> ----------------------------------------

> SELECT to_char(f,
> 'FM999990.99999999999999999999999999999999999999999999999999') FROM t WHERE
> id = 1;

> Expected Output:
> 0.0000000000000000000000000000000563219288

> Actual Output:
> 0.

My immediate reaction to that is that float8 values don't have 57 digits
of precision.  If you are expecting that format string to do something
useful you should be applying it to a numeric column not a double
precision one.

It's possible that we can kluge things to make this particular case work
like you are expecting, but there are always going to be similar-looking
cases that can't work because the precision just isn't there.

(In a quick look at the code, the reason you just get "0." is that it's
rounding off after 15 digits to ensure it doesn't print garbage.  Maybe
it could be a bit smarter for cases where the value is very much smaller
than 1, but it wouldn't be a simple change.)

            regards, tom lane

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

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: Re: BUG #6217: to_char() gives incorrect output for very small float values
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: BUG #6217: to_char() gives incorrect output for very small float values