如何强制VBA进行实数整数运算?

时间:2012-10-12 22:19:02

标签: vba

此代码应返回0,但它返回1. VBA似乎正在进行浮点数学运算,即使所有数字都是长整数。

Function demo() As Long
    Dim const1 As Long
    Dim const2 As Long
    Dim result As Long
    const1 = 1796&
    const2 = 1798&
    result = const1 / const2
    demo = result
End Function

1 个答案:

答案 0 :(得分:4)

更改斜线的方向

Function demo() As Long
    Dim const1 As Long
    Dim const2 As Long
    Dim result As Long
    const1 = 1796&
    const2 = 1798&
    result = const1 \ const2
    demo = result
End Function

\将强制进行整数除法