Re: How to sum monetary variables

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: How to sum monetary variables
Дата
Msg-id CAHyXU0wm2oF_Wceb7oSXy46BdhmbbU85UW8V6jZ3YhEu0jDsuQ@mail.gmail.com
обсуждение исходный текст
Ответ на How to sum monetary variables  (Martín Marqués <martin.marques@gmail.com>)
Ответы Re: How to sum monetary variables
Re: How to sum monetary variables
Список pgsql-general
2011/7/18 Martín Marqués <martin.marques@gmail.com>:
> 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.

I wouldn't even bother testing client implementations that are using
floating point numbers to do the math -- they are going to be wrong.
If you snoop around you should find math libraries that handle do a
better job handling exact numbers for most popular languages.  A few
languages, like the hated COBOL, have them built in.

merlin

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

Предыдущее
От: Martín Marqués
Дата:
Сообщение: How to sum monetary variables
Следующее
От: "Hans C. Poo"
Дата:
Сообщение: Database level read only user