0

我正在尝试在函数中进行计算以得出百分比。但是百分比变量显示为 0。我做错了什么?

Public FullLoopNum as Integer
Public ReportPercentage As Integer
Public ReportRecordNum As Integer

Public Function WebOutput

ReportRecordNum = 1
FullLoopNum = 4

ReportPercentage = (ReportRecordNum \ FullLoopNum)
ReportPercentage = ReportPercentage * 100



End Function
4

2 回答 2

3

使用 Double 类型并将除法运算符更改为正斜杠。

Public FullLoopNum as Integer
Public ReportPercentage As Double
Public ReportRecordNum As Integer

ReportPercentage = (ReportRecordNum * 100 / FullLoopNum) 
于 2013-09-10T16:50:06.480 回答
1

您只使用整数,它们是非浮点(整数)数。您将需要Variant数据类型和CDec函数的组合。像这样的东西:

Public FullLoopNum as Variant
Public ReportPercentage As Variant
Public ReportRecordNum As Variant

ReportPercentage = CDec(ReportRecordNum / FullLoopNum)
ReportPercentage = CDec(ReportPercentage * 100)

我没有对此进行测试,但它应该让您了解如何继续使用CDec. 或者,您可以使用Currency数据类型。

于 2013-09-10T16:45:12.550 回答