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
'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
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
Private Sub Command1_Click() Const x As Single = 12.345 MsgBox "整数位:" & Len(Split(x, ".")(0)) & vbCrLf & "小数位:" & Len(Split(x, ".")(1)) End Sub
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
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
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
Const x As Single = 12.345
MsgBox "整数位:" & Len(Split(x, ".")(0)) & vbCrLf & "小数位:" & Len(Split(x, ".")(1))
End Sub