The ROUND command

When I run this code:

SELECT (517 + 309 + 304 + 282) / 6366.0 AS 'Percent';

I get the correct result set which is 0.221803330191643

Is there a way to refine the query so that the result set is expressed as the whole number 22?

1 Like

You can try CONVERT:

SELECT CONVERT(int, (517 + 309 + 304 + 282) / 6366.0 * 100) AS 'Percent'

Or CONVERT and ROUND:

SELECT CONVERT(int, ROUND((517 + 309 + 304 + 282) / 6366.0 * 100, 0)) AS 'Percent'

The result of both of these is 22, but they might give different results based on the decimal value of the calculation.

You can also just use ROUND:

SELECT ROUND((517 + 309 + 304 + 282) / 6366.0 * 100, 0) AS 'Percent'

The result of this one is 22.000000.

1 Like

That’s exactly what I was looking for Thanks

1 Like