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

Re: Rounding result of expression in SELECT ..AS..

From: "Jean-Yves F(dot) Barbier" <12ukwn(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Rounding result of expression in SELECT ..AS..
Date: 2011-12-15 13:47:20
Message-ID: 20111215144720.5ba2740a@anubis.defcon1 (view raw or flat)
Thread:
Lists: pgsql-novice
On Fri, 16 Dec 2011 00:06:54 +1030
Michael Rowan <mike(dot)rowan(at)internode(dot)on(dot)net> wrote:


> 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?

SELECT TRUNC(myBioutifuelCalcul, NbOfDecimalsWanted);

-- 
Falling in love makes smoking pot all day look like the ultimate in
restraint. -- Dave Sim, author of "Cerebus".

In response to

pgsql-novice by date

Next:From: richard terryDate: 2011-12-16 10:57:40
Subject: question re incrementing an integer field in a table.
Previous:From: Jayadevan MDate: 2011-12-15 13:45:04
Subject: Re: Rounding result of expression in SELECT ..AS..

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