Re: BUG #3791: Bug in aritmethic calculations - Mailing list pgsql-bugs

From Gregory Stark
Subject Re: BUG #3791: Bug in aritmethic calculations
Date
Msg-id 873auocaaa.fsf@oxford.xeocode.com
Whole thread Raw
In response to BUG #3791: Bug in aritmethic calculations  ("Michailas" <michailas.p@gmail.com>)
List pgsql-bugs
"Michailas" <michailas.p@gmail.com> writes:

> postgres=# SELECT abs(300 - 200)/200*100 as bad, abs(300-200)*100/200 as
> good;
>
>  bad | good
> -----+------
>    0 |   50
> (1 row)

That's how integer arithmetic works. Try just 1/2 and you'll see you get 0.
But if you do floating point arithmetic with 1.0/2 you'll get 0.5.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's RemoteDBA services!

pgsql-bugs by date:

Previous
From: "Marek"
Date:
Subject: BUG #3792: cluster in UTF deny database in LATIN2
Next
From: Gregory Stark
Date:
Subject: Re: BUG #3790: pg_restore error canceling statement due to user request