dividing integers not producing decimal fractions - Mailing list pgsql-general

From rloefgren@forethought.net
Subject dividing integers not producing decimal fractions
Date
Msg-id 1162508094.919806.174110@e3g2000cwe.googlegroups.com
Whole thread Raw
Responses Re: dividing integers not producing decimal fractions  (Alexander Staubo <alex@purefiction.net>)
List pgsql-general
I'm trying to produce a decimal fraction by dividing integer fields
like this fragment of the query:

...((cntoh0.count + cntoh1.count)/ttl_deptcat.ttlcount) as "Ratio"...

I get this output

  dept_cat  | cnt_oh_0 | cnt_oh_1 | sum_oh_0+1 | ttl_count | Ratio
------------+----------+----------+------------+-----------+-------
 101500     |      116 |       18 |    134 |   238 |     0
 101800     |      409 |       46 |    455 |   467 |     0
 101900     |      197 |        1 |    198|   198 |     1

Why does "Ratio" display as 0, rather than the proper decimal fraction?
All of the *oh* fields are integers and ttl_count is a bigint. I've
tried wrapping all the integer fields with round(<fieldname>, 3) and I
do get the proper number of zeros to the right of the decimal on the
*oh* fields but not on the "Ratio" field. How do I get fractions when
dividing integers? Cast as something? (I suppose this is going to be
obvious, after-the-fact.)

Thanks for any tips,

r


pgsql-general by date:

Previous
From: "Bobus"
Date:
Subject: fetching unique pins in a high-transaction environment...
Next
From: "Shoaib Mir"
Date:
Subject: Re: Invoking java in a trigger