As an option, if the length of 64 bits does not meet your requirement, try java.math.BigInteger .
This is suitable for situations where the number does not exceed 64 bits.
public static void main(String args[]){ String max_long = "9223372036854775807"; String min_long = "-9223372036854775808"; BigInteger b1 = new BigInteger(max_long); BigInteger b2 = new BigInteger(min_long); BigInteger sum = b1.add(b1); BigInteger difference = b2.subtract(b1); BigInteger product = b1.multiply(b2); BigInteger quotient = b1.divide(b1); System.out.println("The sum is: " + sum); System.out.println("The difference is: " + difference); System.out.println("The product is: " + product); System.out.println("The quotient is: " + quotient); }
Output:
Amount: 18446744073709551614
The difference is as follows: -18446744073709551615
Product: -85070591730234615856620279821087277056
Ratio: 1
Gearon Jul 04 '16 at 1:34 2016-07-04 01:34
source share