VB - 整数除法不包含逗号?
这可能是一个简单的问题,但我有一个 Excel vba 宏,我试图将两个整数相除,最终得到一个整数,即使其中应该有一个逗号。 例如 278 / 101 = 3。虽然它实际上是 2,75 而不是 3。这是为什么?
宏非常简单,如下所示:
Dim intFull, intLow , intDivided as Integer
intFull = 278
intLow = 101
intDivided = intFull \ intLow
This is probably an easy one, but I've got this Excel vba macro where I'm trying to divide two integers and I end up with a round number, even though there should be a comma in there.
For example 278 / 101 = 3. While it's really 2,75 and not 3. Why is this?
The macro is really simple, like this:
Dim intFull, intLow , intDivided as Integer
intFull = 278
intLow = 101
intDivided = intFull \ intLow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的结果变量是一个整数,
如果你使用双精度,你将得到2.752等 - 可以使用
dbDivided = Round(lngFull / lngLow, 2)进行舍入
[变量更新为更有意义]
Your result variables is an integer
If you work with doubles instead you will get 2.752 etc - which can be rounded using
dbDivided = Round(lngFull / lngLow, 2)
[variables updated to be more meaningful]
您确定使用了正斜杠而不是反斜杠吗? (另请参阅:http://zo-d .com/blog/archives/programming/vba-integer-division-and-mod.html)
Sure you used a forward slash and not a backslash? (See also: http://zo-d.com/blog/archives/programming/vba-integer-division-and-mod.html)