SQL - ROUND Function



SQL Tutorial - SQL ROUND Function


The ROUND function is a numeric function that is used to round a numeric value, positive or negative to the specified number of decimals. The data type can be either int (tiny, small, big), decimal, numeric, money or smallmoney.

SQL ROUND SYNTAX


Select ROUND(columnname,decimals) FROM tablename

Note: You can substitute the columnname with a value also.

Round Function Example 1


The Products table has the following records:

ProductID ProductName ProductPrice
Prd001 Pen 40.25
Prd002 Pen 100.75
Prd003 Eraser 10.35
Prd004 Pencil 20.45
Prd005 Book 50.65
Prd006 Gum 25.22

To calculate the price of all the products without the decimal values, use the 'Round' function on the 'ProductPrice' column as shown below.

Select ROUND(ProductPrice,0) as ProductPrice from Products

ProductPrice
40.00
101.00
10.00
20.00
51.00
25.00

Example 2


Now if only a single decimal value is required, you can do so as shown below

Select ROUND(ProductPrice,1) as ProductPrice from Products

ProductPrice
40.30
100.80
10.40
20.50
50.70
25.20