Re: rounding problems

From: Tomasz Ostrowski <tometzky(at)batory(dot)org(dot)pl>
To: Justin <justin(at)emproshunts(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: rounding problems
Date: 2008-05-13 06:40:41
Message-ID: 482937E9.9030509@batory.org.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2008-05-12 20:49, Justin wrote:

> We take (List Price * discount Percent) * Number of Pieces = net
> price.

This is wrong. You should do in Excel:
( price * amount ) * discount
As otherwise any small error in representation of price*discount would
be multiplied by usually high amount.

I'd do this way to get it right:
round( round(price * amount, 2) * discount, 2)
This way every sum should match. There could be errors, but in pennies,
not dollars. These errors will be because Excel does not have a decimal
type.

It is a lost case to break Postgres so it will match Excel. Much easier
would be to correct Excel spreadsheet. And this is a right thing to do.

Regards
Tometzky
--
...although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
Winnie the Pooh

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Volkan YAZICI 2008-05-13 06:52:27 no privileges were granted
Previous Message Martijn van Oosterhout 2008-05-13 06:33:01 Re: Problem returning strings with pgsql 8.3.x