Re: floating point output

Поиск
Список
Период
Сортировка
От Luca Ferrari
Тема Re: floating point output
Дата
Msg-id CAKoxK+53nMQbj4ZdxzMjtXHZa-Uac+kEGnmVduic8mVWi0EjrQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: floating point output  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
On Thu, Sep 5, 2019 at 6:14 AM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> Some examples would help explain your concerns.

I guess the problem is with extra_float_digits. If greater then zero,
the string representation of a real is at its minimum, that is only
significative digits are there:

restoredb=# set extra_float_digits to 1;
SET
restoredb=# select 2.001230::real;
 float4
---------
 2.00123
(1 row)


If lower than zero, the output switch to "precise" mode that is
extra_float_digits are subtracted from the number of available digits
for a number:

restoredb=# set extra_float_digits to -2;
SET
restoredb=# select 2.001230::real;
 float4
--------
  2.001
(1 row)

restoredb=# set extra_float_digits to -3;
SET
restoredb=# select 2.001230::real;
 float4
--------
      2
(1 row)


However, this has some more obscure to me behaviors when the value is
greater than 1:

restoredb=# set extra_float_digits to 1;
SET
restoredb=# select 2.1::real;
 float4
--------
    2.1
(1 row)

restoredb=# set extra_float_digits to 2;
SET
restoredb=# select 2.1::real;
  float4
-----------
 2.0999999
(1 row)


>
> Bottom line, if you want precision use numeric.

Yeah, totally agree. I would also add that numeric is a little more documented.

Luca



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

Предыдущее
От: Luca Ferrari
Дата:
Сообщение: Re: PG11.2 - wal_level =minimal max_wal_senders = 0
Следующее
От: Sonam Sharma
Дата:
Сообщение: Uninstall postgres