BUG #3959: Huge calculation error

Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2008-02-13 이후 PGSQL 사설 토토 사이트 09:53
From: "Renaud Diez" <rdiez(at)salesprize(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3959: Huge calculation error
Date: 2008-02-13 09:53:57
Message-ID: 200802130953.m1D9rv00042872@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2008-02-13 이후 PGSQL 사설 토토 사이트 09:53


The following bug has been logged online:

Bug reference: 3959
Logged by: Renaud Diez
Email address: rdiez(at)salesprize(dot)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.


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Renaud Diez <rdiez(at)salesprize(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3959: Huge calculation error
Date: 2008-02-13 11:24:13
Message-ID: 47B2D35D.1000806@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Renaud Diez wrote:
> The following bug has been logged online:
>
> Bug reference: 3959
> Logged by: Renaud Diez
> Email address: rdiez(at)salesprize(dot)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


From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Renaud Diez" <rdiez(at)salesprize(dot)com>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #3959: Huge calculation error
Date: 2008-02-13 11:24:49
Message-ID: 47B2D381.1010304@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Renaud Diez wrote:
> The following bug has been logged online:
>
> Bug reference: 3959
> Logged by: Renaud Diez
> Email address: rdiez(at)salesprize(dot)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.

That's because 21/100 = 0, in integer math. Try "SELECT
100*(1+(21/100.0))" to use floating points.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Rodriguez Fernando <rodriguez(at)ort(dot)edu(dot)uy>
To: Renaud Diez <rdiez(at)salesprize(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3959: Huge calculation error
Date: 2008-02-13 15:02:34
Message-ID: 47B3068A.6000906@ort.edu.uy
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Renaud Diez wrote:
> The following bug has been logged online:
>
> Bug reference: 3959
> Logged by: Renaud Diez
> Email address: rdiez(at)salesprize(dot)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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
>
Hola, en realidad no lo hace mal, no es lo que esprabas, lo que en
realidad necesitas es esto:
select 100*(1+(21.0/100))::float;
saludos Fernando