BigInteger and BigDecimal are existing classes in the java. math package. The former represents an integer, and the latter represents a floating point.
Why use big numbers?
1) BigInteger: an integer of any precision is supported. It can accurately represent an integer of any size without any information loss During computation.
2) BigInteger: It can accurately represent decimal places of any precision without any information loss during the operation.
Note: you cannot directly use symbols such as + or-to use large numbers. For example:
Import java. math. bigInteger; public class Main {public static void main (String [] args) {int a = 231, B = 423, c = 1393; BigInteger x, y, z, ans; x = BigInteger. valueOf (a); y = BigInteger. valueOf (B); z = BigInteger. valueOf (c); ans = x. add (y); // add System. out. print (ans + ""); ans = z. divide (y); // division operation System. out. print (ans + ""); ans = x. mod (z); // modulo operation System. out. print (ans + ""); if (ans. compareTo (x) = 0) System. out. println ("1 ");}}
Calculation Result: 654 3 231 1
You can use the following methods:
BigInteger add (BigInteger other)
BigInteger subtract (BigInteger other)
BigInteger multiply (BigInteger other)
BigInteger divide (BigInteger other)
BigInteger mod (BigInteger other)
Int compareTo (BigInteger other)
Static BigInteger valueOf (long x)
This article is from the blog of "Italian suckling pig", please be sure to keep this source http://lovesisi.blog.51cto.com/6414433/1301207