Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Resources » Code Snippets » SQL »
How to get integer value from float data
|
Get integer value from float data
We can get integer value from float data by using the simple SQL Server built in functions. We should use as per our requirements. Whether you want to round the value or you want only numeric part? It depends on our need.
There are many ways to to get the numeric part.
Following Mathematical and system functions will do the conversion:- 1) FLOOR 2) CEILING 3) ROUND 4) CAST 5) CONVERT
Sample Code Segment:
DECLARE @fltData FLOAT
SET @fltData = 8.5
/* Syntax: SELECT FLOOR() */
SELECT FLOOR(@fltData)
OUTPUT : 8.0
It returns only numeric part with zero decimal part.
/* Syntax: SELECT CEILING()*/
SELECT CEILING (@fltData)
OUTPUT : 9.0
It returns only numeric part with zero decimal part. It gives rounded value.
/* Syntax: SELECT ROUND(, , )*/
SELECT ROUND(@fltData,0)
OUTPUT : 9.0
It returns only numeric part with zero decimal part. It gives rounded value based on the input data.
/* Syntax: SELECT CAST(, ) */
SELECT CAST (@fltData AS INT)
OUTPUT : 8
It returns only numeric part.
/* Syntax: SELECT CONVERT(, ,
| |