ManishKumar
ManishKumar

Reputation: 1554

How can I convert a float into int using the 'round' method in SQL Server?

I tried with

select ROUND(1235.53) --(It can contain "n" digit of scale)

But I got this error:

The round function requires 2 to 3 arguments.

I am not sure what is the use of other parameters.

Upvotes: 26

Views: 149646

Answers (3)

Stefan Weber
Stefan Weber

Reputation: 21

Here is another approach that just formats the result into the desired format:

SELECT FORMAT(ROUND(1235.53,0), 'N0')

'N' stands for numerical format and the digit behind it controls the number of decimal points.

Upvotes: 1

Better to use CAST INT/CEILING/FLOOR:

SELECT CEILING(1235.53)
SELECT FLOOR(1235.53)
SELECT CAST(1235.53 AS INT)

CEILING: Gives you the upper bound integer value

Enter image description here

FLOOR: Gives you the lower bound integer value

Enter image description here

Upvotes: 36

John Cappelletti
John Cappelletti

Reputation: 82010

Set decimals to zero

select cast(ROUND(1235.53,0) as int)  Returns 1236

select cast(1235.53 as int)           Returns 1235

Upvotes: 43

Related Questions