|
本帖最后由 silenthunter 于 2013-5-29 23:33 编辑
请教,这两个过程哪个更合理?结果都是一样的。
除了我的方法,还有什么方法能判断一个数字是不是小数?
Private Sub test1()
Dim Money As String
Money = Application.InputBox("输入数字", "输入数字", , , , , , 1)
If Money = False Then
MsgBox "没有输入数字。"
Exit Sub
ElseIf InStr(Money, ".") > 0 Then ' 判断输入的数字有没有小数点,大于0表示有小数点。
Money = Left(Money, InStr(Money, ".") - 1) ' 有小数点的话取整数部分。
End If
MsgBox Money
End Sub
Private Sub test2()
Dim Money As String
Money = Application.InputBox("输入数字", "输入数字", , , , , , 1)
If Money = False Then
MsgBox "没有输入数字。"
Exit Sub
ElseIf Int(Money) <> Money Then ' 取整数后不等于原来的数字,说明这个数是小数。
Money = Fix(Money) ' 有小数点的话取整数部分。
End If
MsgBox Money
End Sub
|
|