如题,例如一个小数12.345,怎样得知他的整数位数是两位,小数位数是三位?

解决方案 »

  1.   

    private sub GetNumberLength(byval dblNum as double, byref l1 as integer, byref l2 as integer)  if instr(cstr(dblNum), ".")=0 then
        l1=len(cstr(dblNum))
        l2=0
      else
        l1=len(left(cstr(dblNum), instr(cstr(dblNum), ".")-1))
        l2=len(mid(cstr(dblNum), instr(cstr(dblNum), ".")+1))
      end ifend sub
      

  2.   

    'sgl为小数,nInt为整数位数,nDec为小数位数
    Public Function GetNumLen(ByVal sgl As Single, ByRef nInt As Integer, ByRef nDec As Integer)
        nInt = Len(CStr(Fix(sgl)))    
        If Len(CStr(sgl)) > nInt Then nDec = Len(CStr(sgl)) - nInt - 1    
    End Function
      

  3.   

    If IsNumeric(a) = False Then
            MsgBox "数据非法"
        Else
            GetNumLen a,nInt,nDec 
        End if
    Public Function GetNumLen(ByVal sgl As Single, ByRef nInt As Integer, ByRef nDec As Integer)
        nInt = Len(CStr(Fix(sgl)))    
        If Len(CStr(sgl)) > nInt Then nDec = Len(CStr(sgl)) - nInt - 1    
    End Function
      

  4.   

    Private Sub Command1_Click()
    Const x As Single = 12.345
    MsgBox "整数位:" & Len(Split(x, ".")(0)) & vbCrLf & "小数位:" & Len(Split(x, ".")(1))
    End Sub