TutorialsArena

SQL Server ROUND() Function

The ROUND() function in SQL Server rounds a number to a specified number of decimal places. This is a very common mathematical function for making numbers more concise or for data presentation.



ROUND(): Definition and Usage

ROUND() is used to adjust a number to a certain level of precision. You can round to a specific number of decimal places or to a whole number. The function has an optional parameter to control whether the rounding is done using standard rounding rules or by truncation (chopping off the decimal places without rounding).

Syntax

Syntax

ROUND(number, decimals, operation)
      

Parameter Values

Parameter Description
number The number to be rounded. This is required.
decimals The number of decimal places to round to. A positive number rounds to that many decimal places; a negative number rounds to the left of the decimal point. This is required.
operation (Optional) If 0 (default), standard rounding is used; otherwise (any non-zero value), the number is truncated (decimal places are simply removed).

Related Functions

For rounding down, use FLOOR(). For rounding up, use CEILING().

Examples

Rounding to Two Decimal Places

This rounds 235.415 to two decimal places using standard rounding.

Syntax

SELECT ROUND(235.415, 2) AS RoundValue;
      
Output

235.42
      

Rounding with Truncation

This rounds 235.415 to two decimal places but uses truncation (no rounding).

Syntax

SELECT ROUND(235.415, 2, 1) AS RoundValue;
      
Output

235.41
      

Rounding to a Whole Number

Rounding to the nearest whole number by specifying -1 as the decimal places.

Syntax

SELECT ROUND(235.415, -1) AS RoundValue;
      
Output

240