VBA相当于Excel的mod函数 [英] VBA equivalent to Excel's mod function

查看:241
本文介绍了VBA相当于Excel的mod函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有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:

由于@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆