Search code examples
sqlsql-servernumbersrounding

How do I round -13422.8450 to -13422.84 in SQL Server


I want to round off -13422.8450 as -13422.84 in SQL Server.

But using ROUND(-13422.8450, 2) is returning -13422.85

This is the full query:

SELECT ROUND(CAST(-1 * 50 * 26845.69 / 100 AS NUMERIC(13, 4)), 2)

Solution

  • Add a third parameter having non-zero value to ROUND function; the function will truncate instead of rounding:

    SELECT ROUND(-13422.8450, 2)
    -- -13422.8500
    
    SELECT ROUND(-13422.8450, 2, 1)
    -- -13422.8400
    

    Be advised that casting from numeric to numeric will round the result before the round function is called. In your example you need to round (truncate), then cast.