File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Calculation of large digit-plz help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calculation of large digit-plz help" Watch "Calculation of large digit-plz help" New topic
Author

Calculation of large digit-plz help

Ka Tanaka
Greenhorn

Joined: Jan 29, 2003
Posts: 1
anyone know how to calculate a large number(longer # of digit than long type -> can go up to as long as possible)in java?
the numbers are inputed as string, adding subtracting, multi and div operation are require..thz alot
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
I think if it is longer than long type, what you can do is to define your own function:
1) treat them as string, read in one character at a time.
2) use character comparision to get the number value, then use the normal number calculation.
3) use a loop to calculate every digit from right to left.
4) then depend on what you want as result. If you want string, then you can transform the result back to string again. Or you can use formula below to represent the number value.
N = d_0 * 10^0 + d_1 * 10^1 + ... + d_n * 10^n
HTH.
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Actually, you may have to use this:
N = d_0 + 10 * ( d_1 + 10 * (d_2 + 10 * (d_3 + ( ... ))))
to represent the number value.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
BigInteger


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calculation of large digit-plz help