ROUND Function
Next: SQL CAST Function
The ROUND function in SQL is used to round a number to a specified precision. The syntax is:
ROUND (expression, [decimal place])
where [decimal place] indicates the number of decimal points returned. A negative number means the rounding will occur to the digit to the left of the decimal point. For example, -1 means the number will be rounded to the nearest tens.
Let's go through an example to see how the ROUND function is used. Let's assume we have the following table:
Table Student_Rating
| StudentID | integer |
| First_Name | char(20) |
| Rating | float |
and this table contains the following rows:
Table Student_Rating
| StudentID | First_Name | Rating |
| 1 | Jenny | 85.235 |
| 2 | Bob | 92.52 |
| 3 | Alice | 3.9 |
| 4 | James | 120.1 |
Example 1
SQL:
SELECT First_Name, ROUND(Rating, 1) Rating FROM Student_Rating
Result:
| First_Name | Int_Score |
| Jenny | 85.2 |
| Bob | 92.5 |
| Alice | 3.9 |
| James | 120.1 |
Example 2
SQL:
SELECT First_Name, ROUND(Rating, -1) Rating FROM Student_Rating
Result:
| First_Name | Int_Score |
| Jenny | 90 |
| Bob | 90 |
| Alice | 0 |
| James | 120 |