如何判断一个数是整数或小数

解决方案 »

  1.   

    如果是字符串,用instr()判断是否有小数点,然后小数点后是否全0如果是浮点数,Int()取整,再判断是否相等
      

  2.   

    if a = cint(a) then 
    .......
    else
    ..........
    end if
      

  3.   

    if not isnumeric(a) then
        msgbox "非数值型数据!",48,"提示"
    else
        if a=int(a) then
            msgbox "整数"
        else
            msgbox "小数"
        end if
    end if
      

  4.   

    if InStr(i, ".")>0 then
        整數
    else
        小數
    end if
      

  5.   

    if not isnumeric(a) then
        msgbox "非数值型数据!",48,"提示"
    else
        if InStr(i, ".")>0 then
            整數
        else
            小數
        end if
    end if
      

  6.   

    呵呵~~其實VB中的類型是不很明確的﹐如果是寫成1.0,在VB中會自動變成1,這樣你說它是整數也沒錯.但是如果它是簡單的顯示在DataGrid或MSHFlexGrid表中﹐可以肯定﹐數據源一定不會是整數類型.
      

  7.   

    dim a '*********************
    if not isnumeric(a) then
        msgbox "非数值型数据!",48,"提示"
    else
        if a=int(a) then
            msgbox "整数"
        else
            msgbox "小数"
        end if
    end if
      

  8.   

    先检查有没有小数点
    if 有 then
         再取出小数点右边的数组成另一个数字
         if 这个数大于等于 1 then
              '小数
         else
              '整数
         end if
    else
       '整数end if
      

  9.   

    楼上的不对吧
    测试
    1.1----有点----〉小数
    1.1.1----有点----〉小数
    还是先判断是不是数
    if not isnumeric(a) then