to_char(numeric type, text) rounding instead of truncating

Поиск
Список
Период
Сортировка
От PG Doc comments form
Тема to_char(numeric type, text) rounding instead of truncating
Дата
Msg-id 168991536429.626.9957835774751337210@wrigleys.postgresql.org
обсуждение исходный текст
Ответы Re: to_char(numeric type, text) rounding instead of truncating  (Laurenz Albe <laurenz.albe@cybertec.at>)
Список pgsql-docs
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/15/functions-formatting.html
Description:

I've encountered an issue with to_char(numeric type, text)
Apparently, it uses rounding instead of truncation which leads to
unpexpected results. This is not reflected in the documentation.
My specific example:
select to_Char(1235::real/(2::real+1235::real)*100, '99%')
The expected output was 99%. The output was ##% - since the number was
rounded to 100, there wasn't enough digits in the format.
If I add a digit after the decimal point
select to_char(1235::real/(2::real+1235::real)*100,'90D0%')
The output becomes 99.8%

It would be nice to have this behavior explained in the documentation so
people get more predictable results.

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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Uniquness of ctid
Следующее
От: Laurenz Albe
Дата:
Сообщение: Re: to_char(numeric type, text) rounding instead of truncating