coburne
coburne

Reputation: 149

applying ROUND to 2 columns added together

In the statement below, is there a way to round the final calculation to 4 decimal places? I can only figure out how to apply ROUND to the columns individually.
The columns are both FLOAT.

SELECT (ISNULL([COLUMN A],0) + ISNULL([Column B],0)) AS TOTAL

Upvotes: 1

Views: 61

Answers (2)

fez
fez

Reputation: 1835

You could do this using ROUND() as jarlh mentioned above or alternatively, using CAST() if you want to remove the trailing 0's.

SELECT CAST((ISNULL([COLUMN A],0) + ISNULL([COLUMN B],0)) AS NUMERIC(38,4)) AS TOTAL 

For example:

SELECT ROUND((ISNULL(5.66666,0) + ISNULL(7.22222222,0)) , 4) AS TOTAL -- 12.88890000
SELECT CAST((ISNULL(5.66666,0) + ISNULL(7.22222222,0)) AS NUMERIC(38,4)) AS TOTAL -- 12.8889

Upvotes: 2

HoneyBadger
HoneyBadger

Reputation: 15150

Do you mean something like this?

SELECT ROUND((ISNULL([COLUMN A],0) + ISNULL([Column B],0)), 4) AS TOTAL

edit @jarlh was slightly faster...

Upvotes: 1

Related Questions