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

Rounding result of expression in SELECT ..AS..

From: Michael Rowan <mike(dot)rowan(at)internode(dot)on(dot)net>
To: pgsql-novice novice <pgsql-novice(at)postgresql(dot)org>
Subject: Rounding result of expression in SELECT ..AS..
Date: 2011-12-15 13:36:54
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
I have three columns in my table:
netcost integer(9,2)
taxsum integer(9,2)
quantity integer

In my SELECT I have:

SELECT (netcost+taxsum)*quantity AS totalcost FROM etc etc

My problem is that the value in totalcost is, like, 49.500000000000

SELECT round((netcost+taxsum)*quantity, 2) AS totalcost FROM etc etc

gives the same result.   What I want is 2DP, ie 49.50 in this example.  Is there a way to achieve this?

TIA and for past help.

Michael Rowan

11 Kingscote Street
South Australia 5014

tel 618 8240 3993


pgsql-novice by date

Next:From: Jayadevan MDate: 2011-12-15 13:45:04
Subject: Re: Rounding result of expression in SELECT ..AS..
Previous:From: Pushpendra Singh ThakurDate: 2011-12-15 12:00:33
Subject: Re: Help with installing pgAdmin 3

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group