Precision when substracting two values with SQL

From: Juancho <squid(at)maxiconsumo(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Precision when substracting two values with SQL
Date: 2002-08-12 19:57:32
Message-ID: 3D58132C.6040303@maxiconsumo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hello:
I have a problem substracting two values whith SQL. Please
consider this cases...

ciudadela=# select 0.2-0.2;
?column?
----------
0
(1 row)

That's OK for me,

ciudadela=# select 0.2-0.21;
?column?
----------------------
-0.00999999999999998
(1 row)

I was hoping -0.01,

ciudadela=# select 0.21-0.22;
?column?
----------
-0.01
(1 row)

Again, that's OK for me,

My question is why is this behavior taking place (the second case),
and how can I avoid it.
Any suggestion would be really appreciated.
Thanks,

Juan Manuel
Buenos Aires
Argentina

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tim Ellis 2002-08-12 20:24:07 Re: Precision when substracting two values with SQL
Previous Message Michael Zouroudis 2002-08-12 18:11:06 problem with my insert