views:

191

answers:

3

I have a query returning a column of floating point numbers but I am only interested in the number before the decimal place. I don't want to round the number so I am looking for something like:

1.95 = 1
1.45678 = 1
12.00 = 12
12.9999 = 12

Is there an easy way to achieve this in SqlServer other than doing a substring?

+3  A: 

You can use the floor function.

Andy Jones
Floor does not work for negative numbers - floor(-1.2) yields -2.
Daniel Brückner
Thanks. Floor is the function I was looking for. The numbers are all positive so I can live with the negative numbers issue.
David G
+5  A: 

You can do this -

SELECT CAST(1.230 AS INT)

Output: 1

Kirtan
+1  A: 

You could use ROUND(expression, 0, 1) to truncate a number in T-SQL. See MSDN for reference.

Daniel Brückner