If the basic integer and floating-point precision does not meet the requirements, you can use two very flat useful classes in the Java.math package: BigInteger and BigDecimal. These two classes can handle numeric values that contain a sequence of arbitrary lengths.
BigIntegerclass implements the arbitrary precision of the
integerOperation
BigDecimalThe realization of arbitrary precision
floating point numberThe operation uses a static ValueOf method to convert a normal value to a large value: BigInteger a = biginteger.valueof (100); unfortunately,You cannot use the arithmetic operators (+ *) that people are familiar with to handle large values. Instead, you need to use the add and multiply methods in the large value class BigInteger c = A.add (b)//c = a + bbiginteger D = c.multiply (B.add (biginteger.valueof (2)))//D =c*(b+2)java.math.biginteger1.1BigInteger Add (BigInteger Other) BigInteger subtract (BigInteger other) BigInteger multiply (BigInteger other) BigInteger Divide (BigInteger other) BigInteger mod (BigInteger Other) returns this large integer and another large integer of the and, difference, product, quotient, and remainder int compareTo (BigInteger Other) =other returns 0 <other returns a negative number otherwise returns a positive value static BigInteger valueOf (long x) returns a large integer equal to X
Java.math. BigDecimal 1.1BigDecimal Add (BigDecimal Other) BigDecimal subtract (BigDecimal other) BigDecimal multiply (BigDecimal other) BigDecimal Divide (BigDecimal other Roundingmode mode) 5.0 returns this large real number and another large real number other's and, the difference, the product, the quotient to calculate the quotient, must give the rounding method. ROUNDINGMODE.HALF_UP is rounded way int compareTo (BigDecimal other) =other returns 0 <other returns a negative number otherwise returns a positive number STAITC BigDecimal valueOf (l Ong x) staitc BigDecimal valueOf (long X,int scale) returns a large real number of x or X/10scale
Java basic syntax < five > large value BigInteger BigDecimal