Re: Real type with zero - Mailing list pgsql-general

From Craig Ringer
Subject Re: Real type with zero
Date
Msg-id 4E0B2D9F.4000503@postnewspapers.com.au
Whole thread Raw
In response to Real type with zero  (Condor <condor@stz-bg.com>)
List pgsql-general
On 29/06/2011 7:24 PM, Condor wrote:
> Hello,
> how I can tell my postgresql to store last zero of real type ? I put
> value 2.30 and when I select that column i see 2.3 without zero.

The real data type is an IEEE 754 floating point number. See:

http://en.wikipedia.org/wiki/Floating_point
http://steve.hollasch.net/cgindex/coding/ieeefloat.html

It doesn't store any information about formatting or layout. If you want
to retain that information, you'll need to use NUMERIC or just store
your numbers as formatted strings. Note that NUMERIC doesn't store error
ranges and its formatting isn't preserved by most arithmetic operations;
it's not a full scientific error-bounded numeric type.

regress=> SELECT '4401.00100'::numeric;
   numeric
------------
  4401.00100
(1 row)

regress=> SELECT '4401.00100'::float;
   float8
----------
  4401.001
(1 row)

--
Craig Ringer

pgsql-general by date:

Previous
From: Radoslaw Smogura
Date:
Subject: Re: Real type with zero
Next
From: Magnus Hagander
Date:
Subject: Re: point types in "DISTINCT" queries