請問如何判斷一個數是不是小數?  請大家把算法寫出來.  

解决方案 »

  1.   

    select * from tb where 列%1 = 0 --整数
    select * from tb where 列%1 <> 0 --小数
      

  2.   

    create   table   tb   (proid   int,proarea   varchar(10),proprice decimal(18,2)) 
    insert   into   tb   values( '1 ', 'BJ ',10.05) 
    insert   into   tb   values( '1 ', 'SH ',8) 
    insert   into   tb   values( '1 ', 'GZ ',2) 
    insert   into   tb   values( '2 ', 'BJ ',1.3) 
    insert   into   tb   values( '2 ', 'SH ',3.2)   
    go--小数
    select * 
    from tb
    where cast(substring(cast(proprice as varchar),charindex('.',cast(proprice as varchar))+1,len(cast(proprice as varchar))) as int) <> 0 
    /*
    proid       proarea    proprice             
    ----------- ---------- -------------------- 
    1           BJ         10.05
    2           BJ         1.30
    2           SH         3.20(所影响的行数为 3 行)
    */--整数
    select * 
    from tb
    where cast(substring(cast(proprice as varchar),charindex('.',cast(proprice as varchar))+1,len(cast(proprice as varchar))) as int) = 0 
    /*
    proid       proarea    proprice             
    ----------- ---------- -------------------- 
    1           SH         8.00
    1           GZ         2.00(所影响的行数为 2 行)
    */drop table tb
      

  3.   

      while charindex('.',cast(要判断的数 as char(20))) > 0 then
        print '是小数
      

  4.   

    select * from t where stuff(rtrim(col),1,charindex('.',col),'')>0
      

  5.   

    5.00算不算整数呢,如果算,用floor()取出整数部分,再与原数比比较,相等就是整数,不相等就不是了
      

  6.   

    不要这么麻烦了,这样吧  5.01 > floor(5.01) and 5.01 <ciling(5.01)
    只要满足这样条件的就是带小数位的
      

  7.   

    if cast(substring('12.02',charindex('.',12.02),len(12.02)) as float)>0
    print 0