Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get integer part of number

Tags:

So I have a table with numbers in decimals, say

id    value 2323   2.43 4954  63.98 

And I would like to get

id    value 2323      2 4954     63 

Is there a simple function in T-SQL to do that?

like image 999
dmvianna Avatar asked Oct 31 '12 02:10

dmvianna


People also ask

Which function truncates the fractional part of given number and returns only the integer or whole part?

The TRUNC Function[1] is an Excel Math and Trigonometry function. It removes the fractional part of a number and, thus, truncates a number to an integer. It was introduced in MS Excel 2007. In financial analysis, the function can be used to truncate a number to a given precision.


2 Answers

SELECT FLOOR(value) 

http://msdn.microsoft.com/en-us/library/ms178531.aspx

FLOOR returns the largest integer less than or equal to the specified numeric expression.

like image 53
Stuart Ainsworth Avatar answered Sep 24 '22 17:09

Stuart Ainsworth


Assuming you are OK with truncation of the decimal part you can do: SELECT Id, CAST(value AS INT) INTO IntegerTable FROM NumericTable

like image 21
nipps Avatar answered Sep 22 '22 17:09

nipps