Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

very large number mod problem 1

Status
Not open for further replies.

WorkSuxs

Programmer
Jan 26, 2005
28
US
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.

-DNG
 
forgot to mention that info is from a online resource...

Let me know if that helps you...

-DNG
 
I saw that post as well. But I do need to do a mod on a number that large.

Thanks
 
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
 
Nice, I like that one John, star for you. Now, can you do it in one line? ;)


barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top