|
写的不怎么样,请大家指点
'============================================
'题目3
'AUTHOR: testlab
'DATE : 2009-8-19
'============================================
GetStr()
Public Function GetStr() '输入与输出
str = InputBox("请输入数字")
If (Not IsNumeric(str)) Or InStr(CStr(str),",") Then
MsgBox "此字符串含有非数字的字符,请重新输入"
GetStr()
End If
If str = "" Then
MsgBox ("无输入")
Exit Function
End If
GetStr = dealdata(str)
MsgBox GetStr
End function
Public Function DealData(str) '对数字的处理
If InStr(str,".") = 0 Then
rightdata = ".00"
leftdata = str
Else
num = Split(str,".")
intg = num(0)
decimal = num(1)
End If
If intg <> "" Then
length = Len(intg)
If length > 3 Then
a = length Mod 3
If a <> 0 Then
leftdata = Mid(intg,1,a)&","
End If
i = 1 + b
While i < length - 3
leftdata = leftdata & Mid(intg,i,3) & ","
i = i + 3
Wend
leftdata = leftdata & Mid(intg,length-2,3)
Else
leftdata = intg
End If
Else
leftdata = intg
End If
length = Len(decimal)
If length = 1 Then
rightdata = decimal & "0"
Else
i = 1
While i <= length - 3
rightdata = rightdata & Mid(decimal,i,3) & ","
i = i + 3
Wend
rightdata = rightdata & Mid(decimal,i,3)
End If
DealData = leftdata & "." & rightdata
End Function |
|