Precision when substracting two values with SQL - Mailing list pgsql-admin

From Juancho
Subject Precision when substracting two values with SQL
Date
Msg-id 3D58132C.6040303@maxiconsumo.com
Whole thread Raw
Responses Re: Precision when substracting two values with SQL  (Tim Ellis <Tim.Ellis@gamet.com>)
Re: Precision when substracting two values with SQL  (Andrew Sullivan <andrew@libertyrms.info>)
List 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



pgsql-admin by date:

Previous
From: Michael Zouroudis
Date:
Subject: problem with my insert
Next
From: Tim Ellis
Date:
Subject: Re: Precision when substracting two values with SQL