SQL ROUND() Function


The SQL ROUND() function is used to round a numeric field (floating point value) to the whole number (integer value without fractional) of decimals specified.

The SQL ROUND() function is converting a floating point value to nearest integer value.

Here, round .1 through .4 DOWN to the next lower integer, and .5 through .9 UP to the next higher integer.

Ex: 5.6 will round to 6 and 3.3 will round to 3

The SQL ROUND() function is supports or work with only numeric based columns.

It can be used in any valid SQL SELECT statement as well in SQL where clause.


Search Keys

  • sql round to 2 decimals
  • sql round up
  • sql round to 2 decimal places
  • sql round decimal to 2 places
  • sql round example
  • sql round command
  • sql round function example
  • truncate decimal sql
  • sql decimal function
  • number functions in sql

SQL ROUND() Syntax

The basic syntax is used to round a floating value from a numeric value or expression.


SELECT ROUND(input_number , decimals);

The below syntax is used to round a floating value for a specific table column or field from a specified table.


SELECT ROUND(column_name1 , decimals) FROM table_name1;

Note: The first parameter is used to round the number depends on the input value. The second parameter is used to number of decimal places rounded to and also it is optional parameter. This value must be a positive or negative integer. If this second parameter is omitted, the ROUND() function will round the input number to "0" decimal places.


SQL ROUND() Example - Using Expression Or Formula

The following SQL statement rounds the given input value:


SELECT ROUND(4.1);

The result of above query is:

Expr
4

SQL ROUND() Function More Example

Input Value Result
Round(5.3) 5
Round(6.8) 7
Round(3.5) 4
Round(123.456, 2) 123.460
Round(123.456, 1) 123.500

Sample Database Table - BookInfo

BookId BookName AuthorName BookPrice DomainName
101 Sql Complete Reference Suresh Babu 250.50 Database
102 Sql Commands Haris Karthik 120.30 Database
103 Pl Sql Quick Programming Siva Kumar 150 Programming
104 Sql Query Injection Bala Murugan 199.99 Security
105 The Power Of Pl Sql Suresh Babu 220.80 Programming

SQL ROUND() Example - With Table Column

The following SQL statement selects the bookname and rounds the bookprice in the "BookInfo" table:


SELECT BookName, 
ROUND(BookPrice) As 'Round Price' 
FROM BookInfo;

The result of above query is:

BookName Round Price
Sql Complete Reference 250
Sql Commands 120
Pl Sql Quick Programming 150
Sql Query Injection 200
The Power Of Pl Sql 221

Search Keys

  • sql numeric functions
  • sql server round 2 decimal places
  • sql round function
  • round sql
  • mssql round
  • round function
  • round in sql
  • round function in sql
  • sql round 2 decimals
  • round function in sql server