ROUND Function in SQL

The SQL ROUND function rounds the specified number till the particular decimal places.

Syntax of ROUND String Function

In this ROUND function, following are the three arguments:

  1. Number: It is that decimal number which is to be rounded. Decia
  2. Decimal_places: It can be positive or negative integer which shows the number of decimal places to be round.
  3. Operation: It is optional.

In Structured Query Language, we can also use the ROUND function with the integer columns of the table as shown in the following block:

In this syntax, we used the ROUND function with existing table of SQL. Here, we have to define the name and columns of that table on which we want to perform the ROUND function.

Examples of ROUND String function

Example 1: The following round function rounds the number to -1 decimal places:

Output:

Round_-1Value
950.00

Example 1: The following round function rounds the number to 2 decimal places with third argument which is non-zero:

Output:

Round_-1Value
145.41

Example 3: This example uses the mathematical ROUND function with the SQL table:

In this third example, we will create the new table through which we will perform the ROUND function with the integer columns of the table:

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:

The following SELECT statement displays the inserted records of the above Product_Details table:


Product_IDProduct_NameProduct_QuantityPurchasing_PriceSelling_PriceRelease_DateProduct_Rating
104P110.250945.25481050.25472022-04-308
202P415.50045.24875.57252022-01-285
103P218.250255.248475.7252022-02-184
111P725.2505.95815.9552021-12-259
210P612.65050.95870.9552021-10-1511
212P819.750110.850250.9552022-01-103
112P1024.950550.654835.6572022-04-118

Query 1: The following SELECT query uses the ROUND function with the Product_Quantity column of the above Product_Details table:

Output:

Product_IDProduct_NameProduct_QuantityRound_-1quantity
104P110.25010.000
202P415.50020.000
103P218.25020.000
111P725.25030.000
210P612.65010.000
212P819.75020.000
112P1024.95020.000

Query 2: The following SELECT query uses the ROUND function with the Purchasing_Price and Selling_Price columns of those products whose Product_ID is greater than 103 in the above Product_Details table:

Output:

Product_IDPurchasing_PriceRound_2purcahseSelling_PriceRound_2Sellling
104945.2548945.25001050.25471050.2500
20245.24845.25075.572575.5700
1115.9585.96015.95515.960
21050.95850.96070.95570.960
212110.850110.850250.955250.960
112550.654550.650835.657835.660

Query 3: The following SELECT query uses the ROUND function with the Product_Quantity column of the above Product_Details table:

This function uses the non-zero value, i.e., 1 to the third argument in round function.

Output:

Product_IDProduct_QuantityRound_1_1quantity
10410.25010.200
20215.50015.500
10318.25018.200
11125.25025.200
21012.65012.600
21219.75019.700
11224.95024.900





Latest Courses