Re: 7 decimal digits precision for real - Mailing list pgsql-docs

From Bruce Momjian
Subject Re: 7 decimal digits precision for real
Date
Msg-id 20200803212135.GF17519@momjian.us
Whole thread Raw
In response to 7 decimal digits precision for real  (PG Doc comments form <noreply@postgresql.org>)
List 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@momjian.us>        https://momjian.us
  EnterpriseDB                             https://enterprisedb.com

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




pgsql-docs by date:

Previous
From: Joe Conway
Date:
Subject: Re: [DOCS] Let's document a bytea bug
Next
From: Bruce Momjian
Date:
Subject: Re: "innovative Serializable Snapshot Isolation (SSI) level"