Hi, I have a very large number 123456789012345678 (18 digits long) and I need to do a "mod" on it to get the remainder. Of couse I have looked at what to convert it to. Both double and curreny come up short with overflow errors. Any ideas?
An integer in VBScript is between -32,768 and 32,767. So, CInt() will throw an error if, for example, you try to convert 33,000 to an integer. If your number could be greater than 32,767, use CLng() instead, which has a much higher upper bound (2,147,483,647). If you need even more than that, use CDbl(). Beyond that, convert to a string, because you shouldn't be expecting to use that number for calculations anyway.
By it's nature you can't do a Mod on a floating point number. To find the Mod of a large number, split it into smaller sections each 4 digits long. Take the Mod from the most significant section and prefix the subsequent (4 digit long) sequence. Take the Mod of that sequence and repeat the process to completion.
For example 111222333444555 Mod 4
Take first 4 digits : 1112
1112 Mod 4 = 0
Prefix next 4 digits with the 0: 02233
02233 Mod 4 = 1
Prefix next 4 with the 1: 13444
13444 Mod 4 = 0
Prefix last segment with the 0: 0555
Mod 0555 = 1
Therefore 111222333444555 Mod 4 = 1
Using 4 digits with 1 digit prefix ensures that you don't overflow an Int
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?' Drive a Steam Roller
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.