VB – 除数整数不包括逗号?

这可能是一个容易的,但我有这个Excel VBA的macros,我试图分裂两个整数,我最终以一个整数,即使应该有一个逗号在那里。 例如278/101 = 3.虽然它确实是2,75而不是3,为什么呢?

macros很简单,就像这样:

Dim intFull, intLow , intDivided as Integer intFull = 278 intLow = 101 intDivided = intFull \ intLow 

你的结果variables是一个整数

如果你使用双打,你会得到2.752等 – 可以使用dbDivided = Round(lngFull / lngLow, 2)

[variables更新更有意义]

 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 )