我正在尝试在函数中进行计算以计算出百分比。但百分比变量为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
答案 0 :(得分:3)
使用Double类型并将除法运算符更改为正斜杠。
Public FullLoopNum as Integer
Public ReportPercentage As Double
Public ReportRecordNum As Integer
ReportPercentage = (ReportRecordNum * 100 / FullLoopNum)
答案 1 :(得分: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
数据类型。