代码不计算小数位

Code isn't calculating decimal places

我正在尝试制作一个 VBA 模块来对单元格求和,不包括带有删除线的单元格。我在下面使用的代码效果很好,但不会计算小数。例如,'5 + 5.50' 将等于 10.00 我希望代码将小数值保留到小数点后两位,以便上面的总和为 10.50.

Public Function ExcStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
If Not pRng.Font.Strikethrough Then
xOut = xOut + pRng.Value
End If
Next
ExcStrike = xOut
End Function

为了回答:

Long 数据类型包含整数。

每个 OP:

solution was to change 'As Long' to 'As Single'

我想我应该添加一些关于 Single

的细节

Holds signed IEEE 32-bit (4-byte) single-precision floating-point numbers ranging in value from -3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values. Single-precision numbers store an approximation of a real number.