Skip site navigation (1) Skip section navigation (2)

Re: PostgreSQL FUNCTION return problem

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Rafael Barrera Oro <borafael(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PostgreSQL FUNCTION return problem
Date: 2008-04-07 14:50:54
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Rafael Barrera Oro wrote:
> Hello, i have the following problem and i was wondering if you coulde help
> me. I'll try to describe it as in depth as i can.
>    I have a FUNCTION in a postgresql database which subtracts two DOUBLE
> PRECISION FIELDS and returns the result. The problem is that when the result
> should be zero, the number i
> get is a number ridiculously close to zero in scientific notation (for
> example 2.4697823124E-14) but not zero.

Start here:

The short answer is - never expect the subtraction of two "equal" 
floating point values to be zero. Instead of testing with equality, test 
with a very small range.

If you really need exact values (say, you're working with money) use the 
NUMERIC type instead.

Craig Ringer

In response to

pgsql-jdbc by date

Next:From: Pushker ChaubeyDate: 2008-04-08 11:54:23
Subject: Connection breaks with in transaction with a commit
Previous:From: Rafael Barrera OroDate: 2008-04-07 14:35:22
Subject: PostgreSQL FUNCTION return problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group