# Fractions

Discussion in 'General Developer Questions' started by SanetteWessels, Sep 19, 2003.

1. ### SanetteWesselsNew Member

How do I get to the fraction portion of a float field.

E.g. if the value = 10.5 I need to do a test on the .5 portion.

I tried the following but it is not giving me the correct answer:

DECLARE @fFloat FLOAT
, @iStartString int
, @iLengthString int
, @iEndString int

SET @iStartString = 1
SET @fFloat = 25.5
SET @iLengthString = DATALENGTH(@fFloat)

SELECT @iEndstring = CHARINDEX('.', SUBSTRING(CONVERT(CHAR,@fFloat), @iStartString, @iLengthString)) + @iStartString-1
IF (SELECT CONVERT(FLOAT,SUBSTRING(CONVERT(CHAR,@fFloat),@iEndstring+1, @iLengthString))) > 0
PRINT 'yes'
ELSE PRINT 'no'

yes

If i change the 25.5 to 25.0 it still shows 'yes' and should be 'no'.

Sanette

SQL Developer
JustEnough Software Corporation
Walking on water and coding of a spec is easy, as long as both are frozen - A friend
2. ### bambolaNew Member

declare @fFloat float
select @fFloat = 25.5
select @fFloat - cast(@fFloat as int)

Bambola.
3. ### SanetteWesselsNew Member

Thank you Bambola!<br /><br />Why could I not think of this!!!! <img src='/community/emoticons/emotion-1.gif' alt='' /><br /><br />Sanette
4. ### bambolaNew Member

You just needed a coffee break [<img src='/community/emoticons/emotion-5.gif' alt='' />]<br /><br />Bambola.