Hi,
I am looking for some functions to do addition, subtraction, multiplication and division for numbers of any length. Can anybody help?
Printable View
Hi,
I am looking for some functions to do addition, subtraction, multiplication and division for numbers of any length. Can anybody help?
I saw something in PlanetSourceCode yesterday:
http://www.planetsourcecode.com/vb
Go there and search for "big number"
this may help.
Thanks for your help, I have downloaded the code and will try to decipher it to see how I can modify it to handle numbers above 32K in length - may be add some speed for addition/subtraction. It is the division part that has me stumped!
Andreas
T|Is this big enough?
CURRENCY:
Currency variables are stored as 64-bit (8-byte) numbers in an integer format, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right. This representation provides a range of -922,337,203,685,477.5808 to 922,337,203,685,477.5807. Thetype-declaration character for Currency is the at sign (@).
The Currency data type is useful for calculations involving money and for fixed-point calculations in which accuracy is particularly important.
Hi Vincent,
Thanx for your reply. This is certainly a big number - and a lot of currency (oh, to win the lotto!).
However, I was more thinking along the lines of using strings, with the limitation of the the largest number that can be processed being the length of the string to be stored as a Long Integer - 2^31 in length.
I guess addition could be done in 'chunks', converting parts of the string from right to left into values, doing the addition, checking for a carry, converting to string and taking the next chunk until finished.
I was just hoping that someone might have already done this so I don't have to reinvent the wheel, plus I don't actually do that much VB and it would save me a considerable amount of time.
Regards,
Andreas
Here's more money thatn in Currency: The Decimal 14 bytes: +/-79,228,162,514,264,337,593,543,950,335 with no decimal point;
+/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest