如何判断一个小数的整数位数和小数位数

fei9999 2005-11-01 05:05:25
如题,例如一个小数12.345,怎样得知他的整数位数是两位,小数位数是三位?
...全文
408 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2005-11-01
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Const x As Single = 12.345
MsgBox "整数位:" & Len(Split(x, ".")(0)) & vbCrLf & "小数位:" & Len(Split(x, ".")(1))
End Sub
weiweiplay 2005-11-01
  • 打赏
  • 举报
回复
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
winehero 2005-11-01
  • 打赏
  • 举报
回复
'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
subzero 2005-11-01
  • 打赏
  • 举报
回复
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 if

end sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧