Java basic syntax < five > large value BigInteger BigDecimal

Source: Internet
Author: User
Tags arithmetic operators

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.