Re: BUG #5880: Rounding error when copying a REAL numeric value to DOUBLE PRECISION

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "brad" <smithbs(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5880: Rounding error when copying a REAL numeric value to DOUBLE PRECISION
Date: 2011-02-11 03:22:30
Message-ID: 13053.1297394550@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"brad" <smithbs(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2011-02-11 03:28:01 Re: BUG #5876: Incorrectly reported column value
Previous Message Craig Ringer 2011-02-11 02:59:01 Re: BUG #5879: PostgreSQL can not load my data folder