# SQL - truncating to two decimal places

This query produces stuff like

SELECT
Round( (SUM(Field1 * 100) / Field2, 2) AS MktPct
FROM Table

12.2300000
1.340000

How would i get rid of the extra zeros after the decimal point?
Steve Wales

SELECT
CAST(Round( (SUM(Field1 * 100) / Field2, 2) as decimal(18,2)) AS MktPct
FROM Table

(Adjust the 18 to fit how many significant digits you need)
Assuming you wouldn't want any non-needed zero (even if it's even in the first or second places after the decimal):

SELECT
CONVERT(float, Round( (SUM(Field1 * 100) / Field2, 2)) AS MktPct
FROM Table
Kyle Abrahams, PMP

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
vbnetcoder

I think that is right.

I don't understand the following quote .. could you give me an example of what could go wrong?

"Assuming you wouldn't want any non-needed zero (even if it's even in the first or second places after the decimal):"
I think he means if you have 151.00. Do you want it to display as 151.00 or 151.
Actually, I wrote that before re-reading your heading. You want two decimal places, and I answered as if you would want things like 1.1000000 to look like 1.1 rather than 1.10. The other guys have given you better solutions if you want the cents (2 decimal places) to show. They deserve the points.

You can save the use of FLOAT for something else in the future. :)