Re: PostgreSQL FUNCTION return problem

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: PostgreSQL FUNCTION return problem
Дата
Msg-id 47FA34CE.6030706@postnewspapers.com.au
обсуждение исходный текст
Ответ на PostgreSQL FUNCTION return problem  ("Rafael Barrera Oro" <borafael@gmail.com>)
Список 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:

http://www.google.com/search?q=floating+point+rounding

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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Rafael Barrera Oro"
Дата:
Сообщение: PostgreSQL FUNCTION return problem
Следующее
От: Pushker Chaubey
Дата:
Сообщение: Connection breaks with in transaction with a commit