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

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

posted

0

Actually, you may have to use this: N = d_0 + 10 * ( d_1 + 10 * (d_2 + 10 * (d_3 + ( ... )))) to represent the number value.