VBA Round 函数将数字四舍五入到指定的小数位数。
Round(数字,小数位数)
使用 Round 函数将数字四舍五入到小数点后两位:
Sub RoundExample1()
number = 12.3456
round = Round(number, 2)
MsgBox round '12.35 返回
End Sub
使用 Round 函数对不同的数值进行舍入:
Sub RoundExample2()
MsgBox Round(14.2) '退货:14
MsgBox Round(-14.2) '返回:-14
MsgBox Round("14.2") '退货:14
MsgBox Round("-14.2") '返回:-14
MsgBox Round(9.5) '退货:10
MsgBox Round(-9.5) '回报:-10
MsgBox Round(1.25, 1) '回报:1.2
MsgBox Round(50, 1) '退货:50
MsgBox Round(4532.6351, 2) '回报:4532.64
End Sub