gpt4 book ai didi

vba - 代码不计算小数位

转载 作者:行者123 更新时间:2023-12-02 16:54:48 26 4
gpt4 key购买 nike

我正在尝试制作一个 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 数据类型包含整数。

每个操作:

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.

关于vba - 代码不计算小数位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28502836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com