pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: brad <smithbs@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5880: Rounding error when copying a REAL numeric value to DOUBLE PRECISION
Date: Thu, 10 Feb 2011 22:22:30 -0500
Message-ID: <13053.1297394550@sss.pgh.pa.us> (raw)
In-Reply-To: <201102102338.p1ANcupQ035423@wwwmaster.postgresql.org>
References: <201102102338.p1ANcupQ035423@wwwmaster.postgresql.org>

"brad" <smithbs@gmail.com> writes:
> Steps to recreate are below.  The real value is improperly rounded when
> inserted into a field that is double.  94.31 is stored as 94.3099975585938
> when it is inserted into a double precision column.

This is not a bug, it's just the typical behavior of float arithmetic.
"94.31" doesn't have any exact equivalent in float4, so when you convert
it to a form that is willing to print more decimal places, you find out
that indeed the stored value wasn't quite 94.31.

If this sort of thing makes you uncomfortable, probably you should be
using type "numeric" instead.

			regards, tom lane



view thread (2+ messages)

Message-ID: <13053.1297394550@sss.pgh.pa.us>
Permalink:  ../13053.1297394550@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13053.1297394550@sss.pgh.pa.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, smithbs@gmail.com
  Subject: Re: BUG #5880: Rounding error when copying a REAL numeric value to DOUBLE PRECISION
  In-Reply-To: <13053.1297394550@sss.pgh.pa.us>
  References: <201102102338.p1ANcupQ035423@wwwmaster.postgresql.org> <13053.1297394550@sss.pgh.pa.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