Skip site navigation (1) Skip section navigation (2)

Re: BUG #3959: Huge calculation error

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 (view raw or flat)
Thread:
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

In response to

pgsql-bugs by date

Next:From: Heikki LinnakangasDate: 2008-02-13 11:24:49
Subject: Re: BUG #3959: Huge calculation error
Previous:From: Heikki LinnakangasDate: 2008-02-13 11:09:45
Subject: Re: BUG #3958: Self-Join Group-By Clause Produces Incorrect Results

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group