我想知道是否有人可以帮助我,因为我对我认为是造成简单错误的简单原因视而不见。

我有以下代码:

 doRound1(x1)
  denom1 = 5
  y1 = denom1 - x1 mod denom1
  if y1 <> denom1 then
    x1= x1+y1
  end if

  doRound1=x1
 End function

 'theCalc = 20488888888.684
  theCalc = cDbl(11111111111) * 1.844
  doRound1(theCalc)

我得到这个错误
Microsoft VBScript runtime  error '800a0006'
Overflow: 'x1'

由以上代码中的这一行引起:
 y1 = denom1 - x1 mod denom1

有任何想法吗?就像我说的那样,我这个下午已经失明了。

最佳答案

答案似乎在PRB: "Overflow" with Integer Division and MOD Operator:



答案也可以在这里找到:


Dim dblX as Double
Dim dblY as Double
dblX = 2147483648                ' numerator
dblY = 123                       ' denominator

' round off the numerator and denominator (ensure number is .0)
dblX = INT(dblX + .5)
dblY = INT(dblY + .5)

' Emulate integer division
MsgBox FIX(dblX / dblY)
' Emulate modulo arithmetic
MsgBox dblX - ( dblY * FIX(dblX / dblY) )

关于asp-classic - ASP Classic中的溢出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1433360/

10-09 14:05