SQL > SQL Functions > ROUND Function

The ROUND function in SQL is used to round a number to a specified precision.

Syntax

The syntax for the ROUND function is,

ROUND (expression, [decimal place])

where [decimal place] indicates the number of decimal points returned. A negative number means the rounding will occur to a digit to the left of the decimal point. For example, -1 means the number will be rounded to the nearest tens.

Examples

We use the following table for our examples.

Table Student_Rating

Column NameData Type
StudentIDinteger
First_Namechar(20)
Ratingfloat

and this table contains the following rows:

Table Student_Rating

StudentIDFirst_NameRating
1Jenny85.235
2Bob92.52
3Alice3.9
4James120.1

Example 1: Decimal place is positive

To round to the nearest tenths place, we use the following SQL:

SELECT First_Name, ROUND (Rating, 1) Rounded_Score FROM Student_Rating;

Result:

First_NameRounded_Score
Jenny85.2
Bob92.5
Alice3.9
James120.1

Example 2: Decimal place is negative

To round to the nearest tens place, we use the following SQL:

SELECT First_Name, ROUND (Rating, -1) Rounded_Score FROM Student_Rating;

Result:

First_NameRounded_Score
Jenny90
Bob90
Alice0
James120

Next: SQL String Functions




Copyright © 2017   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact