VBA 、 Int 和 Fix 函数返回数字的整数部分。
Int(数字)
Fix(数字)
使用Int和Fix函数来转换不同类型的数值,这也可以帮助您更好地理解处理负值时的差异:
Sub IntFixExample()
MsgBox Int(1) '退货:1
MsgBox Fix(1) '退货:1
MsgBox Int(-1) '返回:-1
MsgBox Fix(-1) '返回:-1
MsgBox Int(2.9) '退货:2
MsgBox Fix(2.9) '退货:2
MsgBox Int(-2.9) '返回:-3
MsgBox Fix(-2.9) '返回:-2
MsgBox Int(4.5) '退货:4
MsgBox Fix(4.5) '退货:4
MsgBox Int(-4.5) '回报:-5
MsgBox Fix(-4.5) '返回:-4
MsgBox Int(0.424) '返回:0
MsgBox Fix(0.424) '返回:0
MsgBox Int("13") '返回:13
MsgBox Fix("13") '返回:13
MsgBox Int("-4.5") '回报:-5
MsgBox Fix("-4.5") '返回:-4
MsgBox Int(True) '返回:-1
MsgBox Fix(True) '返回:-1
MsgBox Int(False) '返回:0
MsgBox Fix(False) '返回:0
End Sub