How to sum monetary variables

From: Martín Marqués <martin(dot)marques(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: How to sum monetary variables
Date: 2011-07-18 21:59:19
Message-ID: CABeG9LvC+cRA06=h4mU375k50K2ODfqv9KOvAopg8FHg9HPuaw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm building a table (which is a report that has to be printed) with a
bunch of items (up to 300 in some cases) that have unitary price
(stored in a numeric(9,2) field), how many there are, and the total
price for each item. At the end of the table there is a total of all
the items.

The app is running on PHP and PG is the backend.

The question is, how do I get the total of everything?

Running it on PHP gives one value, doing a sum() on the backend gives
another, and I'm starting to notice that even using python as a
calculator gives me errors (big ones). Right now I'm doing the maths
by hand to find out who has the biggest error, or if any is 100%
accurate.

Any ideas?

--
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-07-18 22:04:46 Re: How to sum monetary variables
Previous Message MS Rao 2011-07-18 21:58:14 Programmer ( Postgres), Milwaukee - offsite-Remote - onsite