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