From: Thomas Good <tomg@admin.nrnet.org>
To: pgsql-sql@postgreSQL.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: [SQL] calculating percentages
Date: Tue, 13 Jul 1999 09:30:39 -0400 (EDT)
Message-ID: <Pine.LNX.3.96.990713090122.13446A-100000@admin.nrnet.org> (raw)
In-Reply-To: <m11423F-0000bFC@druid.net>
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 */
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tomg@admin.nrnet.org, tgl@sss.pgh.pa.us
Subject: Re: [SQL] calculating percentages
In-Reply-To: <Pine.LNX.3.96.990713090122.13446A-100000@admin.nrnet.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox