Re: 7 decimal digits precision for real

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: sprakash24oct(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: 7 decimal digits precision for real
Date: 2020-08-03 21:21:35
Message-ID: 20200803212135.GF17519@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Thu, Jul 30, 2020 at 10:31:49PM +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/12/datatype-numeric.html
> Description:
>
> When I try to run
> `insert into employees (r_id) values (3.919192199);`
> where r_id is of type real, I see it stores as 3.9191923 and not 6.
> Am I understanding anything wrong ? isn't the range specified is 6 digits
> precision?

Those extra digits are not guaraneteed to be precise, but usually are
close to accurate, so we include, them. You can diable that with
extra_float_digits = 0:

SELECT '3.919192199'::real;
float4
-----------
3.9191923

SHOW extra_float_digits;
extra_float_digits
--------------------
1

SET extra_float_digits = 0;
SELECT '3.919192199'::real;
float4
---------
3.91919

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EnterpriseDB https://enterprisedb.com

The usefulness of a cup is in its emptiness, Bruce Lee

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Alvaro Herrera 2020-08-03 21:39:47 Re: [DOCS] Let's document a bytea bug
Previous Message Bruce Momjian 2020-08-03 21:04:13 Re: [DOCS] Let's document a bytea bug