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

Rounding result of expression in SELECT ..AS..

From
Michael Rowan
Date:
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
mike.rowan@internode.on.net

11 Kingscote Street
ALBERTON
South Australia 5014

tel 618 8240 3993




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

From
"Jean-Yves F. Barbier"
Date:
On Fri, 16 Dec 2011 00:06:54 +1030
Michael Rowan <mike.rowan@internode.on.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".

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

From
Jayadevan M
Date:
Hello,
> I have three columns in my table:
> netcost integer(9,2)
> taxsum integer(9,2)
> quantity integer
How did you create a table with  integer(9,2) as data type? Could you please share the create table command and data insertion statements for a couple of records?

Regards,
Jayadevan





DISCLAIMER:


"The information in this e-mail and any attachment is intended only for the person to whom it is addressed and may contain confidential and/or privileged material. If you have received this e-mail in error, kindly contact the sender and destroy all copies of the original communication. IBS makes no warranty, express or implied, nor guarantees the accuracy, adequacy or completeness of the information contained in this email or any attachment and is not liable for any errors, defects, omissions, viruses or for resultant loss or damage, if any, direct or indirect."