"44" Java Large numerical analysis

Source: Internet
Author: User

The basic integer and float precision does not meet the requirements, then you can use the two classes in Java.math: BigInteger and BigDecimal.

BigInteger and BigDecimal Introduction:

These two classes can handle numeric values that contain sequences of any length.
The BigInteger class implements an integer calculation of arbitrary precision. BigDecimal realizes the calculation of floating-point number with arbitrary precision.

Use the static ValueOf method to convert a normal value to a large value

BigInteger a = BigInteger.valueOf(100);

Use:

BIgInteger C = a.add (b);(C = a+b;)
Biginterger d = c.multiply (B.add (biginteger.valueof (2)));(d = c* (b+2));

BigInteger's API Description:

Add (BigInteger a)//Plus
Subtract (BigInteger a)//subtraction
Multiply (BigInteger a)//multiplication
Divide (BigInteger a)//division
MoD (BigInteger a)//Find redundancy
CompareTo (BigInteger a)//equals return 0. Less than negative, greater than positive
ValueOf (long x)//large integer that returns x

Bigdecamal's API Description:

Add (BigDecimal a)//Plus
Subtract (BigDecimal a)//subtraction
Multiply (BigDecimal a)//multiplication
Divide (BigDecimal a)//division
CompareTo (BigDecimal a)//rules with Bigineger
ValueOf (long x)

Welcome to the group: public number It face questions summary discussion group

If the scan does not go in, add me (rdst6029930) pull you. Sweep my QR code plus me

You are welcome to pay attention to the "It question summary" subscription number. Every day to push the classic face test and interview tips, are dry! The QR code of the subscription number is as follows:

"44" Java Large numerical analysis

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.