Re: BUG #3959: Huge calculation error - Mailing list pgsql-bugs

From Magnus Hagander
Subject Re: BUG #3959: Huge calculation error
Date
Msg-id 47B2D35D.1000806@hagander.net
Whole thread Raw
In response to BUG #3959: Huge calculation error  ("Renaud Diez" <rdiez@salesprize.com>)
List pgsql-bugs
Renaud Diez wrote:
> The following bug has been logged online:
>
> Bug reference:      3959
> Logged by:          Renaud Diez
> Email address:      rdiez@salesprize.com
> PostgreSQL version: 8.2
> Operating system:   Debian
> Description:        Huge calculation error
> Details:
>
> the basic mathematical expression like the following one doesn't compute the
> correct result:
>
>> select 100*(1+(21/100));
>
> return a result of 100 instead of 121.

It does compute the correct result, because you're doing integer
calculations. 21/100 for integers is 0. To make it do float calc, you can do
select 100*(1+(21::float/100));

Or you can do
select 100*(1+(21.0/100));

which will force it to numeric.

//Magnus

pgsql-bugs by date:

Previous
From: "Renaud Diez"
Date:
Subject: BUG #3959: Huge calculation error
Next
From: "Heikki Linnakangas"
Date:
Subject: Re: BUG #3959: Huge calculation error