Option ExplicitDim x As Integer
Sub test1() x = 6.5 MsgBox xEnd Sub
Sub test2() x = 7.5 MsgBox xEnd Sub
为什么test2()返回8,而不是7?
谢谢!
自动四舍五入。
至于为什么是8,就是VBA.Round和Worksheetfunction.Round的区别。
两个方法不一样的:当精度的后一位是5,看前一位。
VBA.Round是凑偶数的。
Worksheetfunction.Round没上述限制。
这里四舍五入采用的是VBA.Round
使用道具 举报
[em04][em04]
默认类型是整型,你的是7.5,四舍五入啊
谢谢雨狐!!
我也只知道要舍入 [em04]
而不知道舍入的标准,比如1楼例子。
如果是四舍五入,那 .................... test1()为什么返回6,而不是7?
凑偶数,学习了,真没注意过!
可是,我这样试了下:
Sub test3()
Dim x As Integer x = 7.5 MsgBox x MsgBox VBA.Round(x, 0) MsgBox Application.WorksheetFunction.Round(x, 0) End Sub
无论x=6.5还是7.5,三句msgbox返回的结果都一样?
对啊
发现了和爱疯同样的问题 为什么 6.5返回6 ,而7.5返回8
思考中……
Sub test4()
Dim x As Integer x = 6.5 MsgBox x MsgBox VBA.Round(x, 0) MsgBox Application.WorksheetFunction.Round(x, 0) x = 7.5 MsgBox x MsgBox VBA.Round(x, 0) MsgBox Application.WorksheetFunction.Round(x, 0)End Sub
本版积分规则 发表回复 回帖后跳转到最后一页
小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )
GMT+8, 2024-6-3 16:21 , Processed in 0.274184 second(s), 4 queries , Gzip On, Yac On.
Powered by Discuz! X3.4
Copyright © 2001-2020, Tencent Cloud.