Re: Real type with zero

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: condor(at)stz-bg(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Real type with zero
Date: 2011-06-29 13:50:23
Message-ID: 4E0B2D9F.4000503@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2011-06-29 14:25:46 Re: point types in "DISTINCT" queries
Previous Message Radoslaw Smogura 2011-06-29 12:40:35 Re: Real type with zero