Received: from mail2.panix.com (mail2.panix.com [166.84.0.213]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA95032 for ; Tue, 13 Jul 1999 10:10:25 -0400 (EDT) (envelope-from tomg@admin.nrnet.org) Received: from mailhost.nrnet.org (mailhost.nrnet.org [166.84.192.39]) by mail2.panix.com (Postfix) with ESMTP id 6F0DB4E3; Tue, 13 Jul 1999 10:10:14 -0400 (EDT) Received: from admin.nrnet.org (uucp@localhost) by mailhost.nrnet.org (8.8.7/8.8.4) with UUCP id JAA04826; Tue, 13 Jul 1999 09:28:59 -0400 Received: from localhost (tomg@localhost) by admin.nrnet.org (8.8.7/8.8.7) with SMTP id JAA14190; Tue, 13 Jul 1999 09:30:40 -0400 Date: Tue, 13 Jul 1999 09:30:39 -0400 (EDT) From: Thomas Good To: pgsql-sql@postgreSQL.org Cc: tgl@sss.pgh.pa.us Subject: Re: [SQL] calculating percentages In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 */