Mod()
operates on integer values. If the value you're passing isn't an integer value, VBScript will convert it to one by rounding it to the nearest integer. That's what's happening with your value of 1705. After three iterations, you're left with 1.705, which Mod()
rounds to 2.
So now the question becomes, why are you passing floating-point values to Mod()
in the first place? The reason is because VBScript is doing floating point division in the following statement:
val = val / base
Since you don't care about the remainder (you've already captured it), this statement needs to be performing integer division, not floating-point division. Fortunately, VBScript makes integer division easy. Just use a backslash instead of a forward slash:
val = val \ base