SQL Server ROUND Function: How to Use It
In this article
The SQL Server ROUND function returns a number rounded to a specified number of decimal places. The basic syntax is ROUND(numeric_expression, length [, function]). The third argument is optional: if you omit it or pass 0, the value is rounded; if you pass any nonzero value, the value is truncated instead. For example, SELECT ROUND(123.4567, 2) returns 123.4600, while SELECT ROUND(123.4567, 2, 1) returns 123.4500. That single optional argument is the source of most confusion, so the steps below walk through both behaviors, negative lengths, data types, and the edge cases that trip people up.
What You'll Need
- Access to a SQL Server instance (any recent version works; the ROUND function has been stable for many versions).
- A client tool such as SQL Server Management Studio (SSMS), Azure Data Studio, or the
sqlcmdutility. - Permission to run a
SELECTstatement in at least one database. No special privileges are required for scalar functions. - A test table or a few literal values to experiment with. You do not need to modify any existing data to learn how ROUND behaves.
Step-by-Step
- Open a query window. In SSMS, connect to your instance and click New Query. In Azure Data Studio, use File > New Query. The exact menu labels can differ slightly by version and client, but the concept is the same: you need a blank editor connected to a database.
- Select a database context. Run
USE YourDatabaseName;so you are not accidentally working inmaster. For pure literal tests this is not strictly required, but it is a good habit and avoids surprises when you later reference tables. - Round to a positive number of decimal places. Run:
SELECT ROUND(123.4567, 2) AS Rounded;
The result is 123.4600. Notice that the result keeps trailing zeros because the return type follows the input's precision and scale, not the rounded value. If you expected 123.46 without zeros, that is a display/type issue, not a rounding issue. - Round to zero decimal places. Run:
SELECT ROUND(123.4567, 0) AS Rounded;
This returns 123.0000. Again, the scale is preserved. To drop the trailing zeros in output, cast the result, for exampleCAST(ROUND(123.4567, 0) AS DECIMAL(10,0)). - Round to a negative number of decimal places. Run:
SELECT ROUND(123.4567, -1) AS Tens, ROUND(123.4567, -2) AS Hundreds;
The first returns 120.0000 and the second returns 100.0000. A negative length rounds to the left of the decimal point: -1 rounds to the nearest ten, -2 to the nearest hundred, and so on. This is handy for reporting figures in thousands or millions. - Truncate instead of round. Run:
SELECT ROUND(123.4567, 2, 1) AS Truncated;
The third argument, when nonzero, tells SQL Server to truncate rather than round. The result is 123.4500. Any nonzero value works; 1 is conventional. This is the only built-in way to truncate decimals with ROUND, and it is often mistaken for a separate function. - Test the midpoint behavior. Run:
SELECT ROUND(2.5, 0) AS Up, ROUND(3.5, 0) AS AlsoUp, ROUND(-2.5, 0) AS Negative;
SQL Server rounds half away from zero, so 2.5 becomes 3, 3.5 becomes 4, and -2.5 becomes -3. This differs from banker's rounding (round half to even) used by some other systems, so do not assume the behavior carries over. - Apply ROUND to a column. Create a small test table:
CREATE TABLE #Prices (Amount DECIMAL(10,4));
INSERT INTO #Prices VALUES (19.9876), (5.5555), (100.1234);
SELECT Amount, ROUND(Amount, 2) AS RoundedAmount FROM #Prices;
This shows ROUND working row by row. The#prefix creates a temporary table that disappears when your session ends, so you are not touching production data. - Combine ROUND with CAST for clean output. Run:
SELECT CAST(ROUND(Amount, 2) AS DECIMAL(10,2)) AS CleanAmount FROM #Prices;
Casting after rounding removes the extra trailing zeros and gives you a value with exactly the scale you want. This is the pattern most reporting queries use. - Check the data type of the result. Run:
SELECT SQL_VARIANT_PROPERTY(ROUND(CAST(123.4567 AS FLOAT), 2), 'BaseType') AS ResultType;
The return type of ROUND matches the input type. If you pass aFLOAT, you get aFLOATback, and floating-point representation can produce surprising last digits. For money-like values, useDECIMALorNUMERICas the input.
Common Mistakes
- Expecting ROUND to change the column's stored type. ROUND returns a value; it does not alter the underlying column definition. To permanently store rounded values you must
UPDATEthe column or insert into a new column with the desired type. - Confusing rounding with formatting. ROUND changes the numeric value. If you only want to display two decimals, use
FORMATorCASTfor presentation, and reserve ROUND for calculations. - Assuming banker's rounding. SQL Server rounds half away from zero. If your application expects half-to-even, you will see differences at exact midpoints.
- Passing a negative length by accident. A length of -1 rounds to tens, not to one decimal place. Double-check the sign, especially when the length comes from a variable.
- Using ROUND on FLOAT for financial data. Binary floating point cannot represent many decimal fractions exactly, so rounding a FLOAT can yield values like 123.449999 instead of 123.45. Use DECIMAL for money.
- Forgetting the third argument is a truncation flag, not a rounding mode. Any nonzero value truncates; it does not select a different rounding rule.
Tips
- Use
DECIMAL(p,s)for monetary and other exact values, and set the scale to the number of decimals you need. ROUND then behaves predictably. - When you need clean output without trailing zeros, wrap the rounded value in
CAST(... AS DECIMAL(p,s))with the exact scale you want. - For truncation,
ROUND(value, length, 1)is the standard trick. There is no separate TRUNCATE function for numbers in T-SQL. - Negative lengths are useful for dashboards:
ROUND(1234567, -3)gives 1235000.0000, which reads as roughly 1.24 million when formatted. - Test midpoint values (x.5) explicitly whenever you change data types or migrate logic between systems, because rounding rules differ across platforms.
- Remember that ROUND does not change the precision or scale of the return type. Plan your casts accordingly.
Troubleshooting
If your rounded value still shows many decimal places, check the data type of the input and the result. A DECIMAL(10,4) input rounded to 2 places still returns a DECIMAL(10,4) value with two trailing zeros. Cast the result to the scale you want if the display matters.
If you see unexpected digits at the end of a FLOAT result, switch the input to DECIMAL or NUMERIC. Binary floating point cannot represent every decimal fraction exactly, and no amount of rounding will fix the underlying representation.
If a midpoint rounds the "wrong" way compared with another system, confirm the rule: SQL Server rounds half away from zero. If your business rule requires half-to-even, you must implement it manually with a CASE expression or a custom formula; ROUND does not offer that mode.
If you get an error about argument types, check that the first argument is numeric and the second is an integer. Passing a string that cannot be implicitly converted will raise a conversion error. Convert explicitly with CAST or TRY_CAST.
If a negative length gives a surprising result, remember it rounds to the left of the decimal point. For example, ROUND(149, -2) returns 100, not 150, because 149 is closer to 100 than to 200.
If you need to round and then store the result, use an UPDATE with the cast applied, and test on a copy of the table first. Rounding in a SELECT does not persist anything.
Frequently Asked Questions
Does ROUND change the data type of the result?
No. ROUND returns the same data type as its first argument, including precision and scale. Use CAST if you need a different scale in the output.
How do I truncate instead of round in SQL Server?
Pass a nonzero third argument: ROUND(value, length, 1). Any nonzero value truncates; there is no separate numeric TRUNCATE function in T-SQL.
Why does ROUND(2.5, 0) return 3 and not 2?
SQL Server rounds half away from zero, so 2.5 becomes 3 and -2.5 becomes -3. This differs from banker's rounding used by some other systems.
Can I use ROUND with a negative length?
Yes. A negative length rounds to the left of the decimal point: -1 rounds to tens, -2 to hundreds, and so on.
Why does ROUND(123.4567, 2) show 123.4600 instead of 123.46?
The return type keeps the input's scale, so trailing zeros are preserved. Cast the result to DECIMAL(10,2) if you want exactly two decimals displayed.
Is ROUND safe to use on FLOAT columns for money?
It is not recommended. FLOAT cannot represent many decimal fractions exactly, so results can show unexpected trailing digits. Use DECIMAL or NUMERIC for monetary values.