Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Math FunctionsRSS Feeds

ROUND Function

Posted By: Sarita Patel     Category: SQL Server     Views: 6561

This article explains ROUND function of sql server with examples.

ROUND function is used to round number by specified length pr precision.


Syntax of ROUND Function :

ROUND ( numeric_expression , length [ ,function ] )

numeric_expression is a number or approximate number data type except bit. 

length is the precision. It can be of type int, smallint or tinyint. If it is positive then decimal part of a number is rounded and if it is negative then number is rounded on the left side of the decimal point.

function specifies the type of operation to perform. It can be of data type int, smallint or tinyint. If you dont specify value for function or specify value 0 then the numeric_expression is rounded and when you specify value other then 0 then it is truncated.

Return type of SQUARE function is same as specified numeric expression.



Examples of ROUND Function :

Example 1 : Use of ROUND function in select clause

SELECT ROUND(123.576,2), ROUND(123.123,2)

Output
123.580 123.120

Above example returns rounded values in decimal part of specified number by 2 digits.



Example 2 : Use of ROUND function in select clause


SELECT ROUND(567.655,-2), ROUND(512.566,-2)

Output
600.000 500.000

Above example rounded values on the left side of decimal point of the specified number by 2 digits.



Example 3 : Use of ROUND function to get rounded and truncated values in select clause

SELECT  ROUND(560.80,0), ROUND(560.80,0,1)

Output
561.00 560.00

In above example 1st value is rounded annd 2nd value is truncated.
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on ROUND Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of ROUND Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!