这可能是一个简单的,但我有这个 Excel vba 宏,我试图将两个整数相除,我最终得到一个整数,即使那里应该有一个逗号。例如 278 / 101 = 3。虽然它实际上是 2,75 而不是 3。这是为什么呢?
这个宏真的很简单,像这样:
Dim intFull, intLow , intDivided as Integer
intFull = 278
intLow = 101
intDivided = intFull \ intLow
你的结果变量是一个整数
如果您使用双打代替,您将得到 2.752 等 - 可以使用四舍五入dbDivided = Round(lngFull / lngLow, 2)
[变量更新更有意义]
Sub redone()
Dim lngFull As Long
Dim lngLow As Long
Dim dbDivided As Double
lngFull = 278
lngLow = 101
dbDivided = Round(lngFull / lngLow, 2)
End Sub
确定您使用的是正斜杠而不是反斜杠?(另见:http: //zo-d.com/blog/archives/programming/vba-integer-division-and-mod.html)