Re: Precision when substracting two values with SQL

From: Larry Rosenman <ler(at)lerctr(dot)org>
To: Tim Ellis <Tim(dot)Ellis(at)gamet(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Precision when substracting two values with SQL
Date: 2002-08-12 20:27:01
Message-ID: 1029184021.473.35.camel@lerlaptop.iadfw.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, 2002-08-12 at 15:24, Tim Ellis wrote:
> > ciudadela=# select 0.2-0.2;
> > 0
> > ciudadela=# select 0.2-0.21;
> > -0.00999999999999998
> > ciudadela=# select 0.21-0.22;
> > -0.01
>
> I also get this on my Postgres 7.2.1, both Linux and Solaris.
You are comparing floats.

This is a STANDARD problem with Base 10 Floating point.

LER

--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: ler(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Andrew Sullivan 2002-08-12 20:27:42 Re: Precision when substracting two values with SQL
Previous Message Tim Ellis 2002-08-12 20:24:07 Re: Precision when substracting two values with SQL