SQL Server Performance


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

  1. SanetteWessels New 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:

    , @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'


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

    Thanks in advance!


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

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

  3. SanetteWessels New 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. bambola New Member

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

Share This Page