pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: sprakash24oct@gmail.com
To: pgsql-docs@lists.postgresql.org
Subject: Re: 7 decimal digits precision for real
Date: Mon, 3 Aug 2020 17:21:35 -0400
Message-ID: <20200803212135.GF17519@momjian.us> (raw)
In-Reply-To: <159614830974.681.17017141356953934189@wrigleys.postgresql.org>
References: <159614830974.681.17017141356953934189@wrigleys.postgresql.org>

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






Message-ID: <20200803212135.GF17519@momjian.us>
Permalink:  ../20200803212135.GF17519@momjian.us/
Also on:    postgresql.org/message-id/20200803212135.GF17519@momjian.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: bruce@momjian.us, sprakash24oct@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: 7 decimal digits precision for real
  In-Reply-To: <20200803212135.GF17519@momjian.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox