VBA相当于Excel的mod函数 [英] VBA equivalent to Excel's mod function
问题描述
有没有vba等价于excel的 mod
函数?
Is there a vba equivalent to excel's mod
function?
推荐答案
您希望 mod运算符。
The expression a Mod b is equivalent to the following formula:
a - (b * (a \ b))
已编辑添加:
有一些特殊情况可能需要考虑,因为Excel使用浮点数学(并返回一个 float
),VBA函数返回一个整数。因此,使用浮点数的 mod
可能需要特别注意:
There are some special cases you may have to consider, because Excel is using floating point math (and returns a float
), which the VBA function returns an integer. Because of this, using mod
with floating-point numbers may require extra attention:
-
Excel的结果可能与您预测的结果不一致;这简要介绍了这里(请参阅最上面的答案),并在很大程度上这里。
由于@André在评论中指出,负数可能与您期望的方向相反。 Fix()
功能,他建议说明这里(MSDN)。
As @André points out in the comments, negative numbers may round in the opposite direction from what you expect. The Fix()
function he suggests is explained here (MSDN).
这篇关于VBA相当于Excel的mod函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!