| From: | Thomas Good <tomg(at)admin(dot)nrnet(dot)org> |
|---|---|
| To: | pgsql-sql(at)postgreSQL(dot)org |
| Cc: | tgl(at)sss(dot)pgh(dot)pa(dot)us |
| Subject: | Re: [SQL] calculating percentages |
| Date: | 1999-07-13 13:30:39 |
| Message-ID: | Pine.LNX.3.96.990713090122.13446A-100000@admin.nrnet.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Tue, 13 Jul 1999, D'Arcy J.M. Cain wrote:
> Thus spake Thomas Good
> > > > How does one do this: SELECT (current_value/target) * 100;
> > The divison rtns 0, which multiplied by 100, rtns 0.
>
> Does "SELECT (current_value * 100)/target" work better?
Darcy,
SELECT (2 * 100)/3;
?column?
----------------
66
(1 row)
This is clean and I don't have to truncate the value in the end.
Thanks!
BTW, I noticed an idiosnycratic behaviour that I don't really
care for when doing floating point calculations:
SELECT (2::float8/3::float8) * 100;
?column?
----------------
66.6666666666667 <----------------- I don't need to round up here.
(1 row)
EOF
So, Larry W comes in handy again:
#!/usr/bin/perl
$val = (2/3) * 100;
print("$val\n");
66.6666666666666
------- North Richmond Community Mental Health Center -------
Thomas Good MIS Coordinator
Vital Signs: tomg@ { admin | q8 } .nrnet.org
Phone: 718-354-5528
Fax: 718-354-5056
/* Member: Computer Professionals For Social Responsibility */
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 1999-07-13 14:01:55 | Re: [SQL] Postgres ERROR |
| Previous Message | D'Arcy J.M. Cain | 1999-07-13 12:52:49 | Re: [SQL] calculating percentages |