Re: strange sum behaviour

From: "Karen Hill" <karen_hill22(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: strange sum behaviour
Date: 2006-08-29 17:31:05
Message-ID: 1156872665.455452.289830@m73g2000cwd.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


"Andrew Baerg" wrote:
> Hi,
>
> I am getting strange results from the sum function as follows:
>
> corp=# select amount from acc_trans where trans_id=19721 and chart_id=10019;
> amount
> ---------
> 4.88
> 117.1
> -121.98
> (3 rows)
>
> corp=# select sum(amount) from acc_trans where trans_id=19721 and
> chart_id=10019;
> sum
> ----------------------
> -1.4210854715202e-14
> (1 row)
>
>
> amount is defined as double precision. I noticed that if I cast amount
> as numeric, the sum comes out 0 as expected.
>

You are using the wrong datatype if you are working with currency. Use
Numeric or Decimal instead. The "money" type is depreciated.

http://www.postgresql.org/docs/8.1/interactive/datatype-money.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2006-08-29 17:57:55 Re: strange sum behaviour
Previous Message Jasbinder Bali 2006-08-29 17:29:28 Re: Shared Objects (Dynamic loading)