我从服务器获取本周的收入和上周的收入值并将其保存为: RevenueThisWeek = objRevenueThisWeek(“REVENUE”) RevenueLastWeek = objRevenueLastWeek(“REVENUE”) 然后,我计算它们的百分比为: RevenuePercent = RevenueThisWeek - RevenueLastWeek RevenuePercent = RevenuePercent / RevenueLastWeek RevenuePercent = RevenuePercent * 100
问题是,如果RevenueThisWeek和RevenueLastWeek都为0,则会收到以下错误消息。
Microsoft VBScript运行时错误“800a0006”
溢出
忘了提。我创建了一个if语句为
If (RevenueThisWeek AND RevenueLastWeek) = "0" Then
Else
RevenuePercent = RevenueThisWeek - RevenueLastWeek
RevenuePercent = RevenuePercent / RevenueLastWeek
RevenuePercent = RevenuePercent * 100
End If
但这给了我如下结果:
Last Week This Week % Change
Revenue $49.99 $72.97 0%
答案 0 :(得分:3)
答案 1 :(得分:2)
RevenuePercent = RevenueThisWeek - RevenueLastWeek
If RevenueLastWeek >= .01 Then '1 cent minimum. >0 can get messy.'
RevenuePercent = RevenuePercent / RevenueLastWeek
Else
RevenuePercent = 0
End If
RevenuePercent = RevenuePercent * 100
为什么> .01?
VBScript没有十进制类型,默认为浮点数,这意味着你最终可能会得到一个值为.0000004505或丑陋的东西,这仍然会导致溢出。如果你处理十分之一美分将其改为
If RevenueLastWeek >= .001 Then
答案 2 :(得分:1)
好吧,您要求ASP执行以下计算:
RevenuePercent = RevenueThisWeek - RevenueLastWeek
RevenuePercent = RevenuePercent / RevenueLastWeek
RevenuePercent = RevenuePercent * 100
或者,给出RevenueThisWeek和RevenueLastWeek的数字0:
RevenuePercent = 0 - 0
RevenuePercent = 0/0
RevenuePercent = 0*100
问题线实际上是中间计算:
RevenuePercent = 0/0
因为你要求计算机除以0 - 这是不可能的。您需要在以下伪代码的行中添加IF语句:
IF RevenueLastWeek>0 THEN ...perform calculation.. ELSE RevenuePercent=0 ENDIF
答案 3 :(得分:0)
基本上这就是你在做的事情:
RevenuePercent =(objRevenueThisWeek(“REVENUE”) - objRevenueLastWeek(“REVENUE”))* 100 / objRevenueLastWeek(“REVENUE”)
如果objRevenueLastWeek(“REVENUE”)= 0,那么你除以0,因此 溢出。您可能需要一个条件来解释此案例。
-