C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » SQL »

How to get integer value from float data


Posted Date: 26 Oct 2009    Resource Type: Code Snippets    Category: SQL
Author: MelchiorMember Level: Gold    
Rating: 1 out of 5Points: 10



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(, , ) */

SELECT CONVERT(INT, @fltData)

OUTPUT : 8

It returns only numeric part.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Data Convesion : Float To Int  .  Data Conversion : Float To Integer value  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to Execute Stored Procedure
Previous Resource: Select nth Maximum value without using RANK / MAX
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use