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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: BUG #3791: Bug in aritmethic calculations



"Michailas" <michailas(dot)p(at)gmail(dot)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!



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group