Basic functions of Java large number class BigInteger and BigDecimal

Source: Internet
Author: User
Tags greatest common divisor pow

In Java there are two classes BigInteger and bigdecimal that represent immutable arbitrary-precision integers and immutable signed arbitrary-precision decimal numbers (floating-point numbers). It is mainly used in high precision calculation. These two classes make large numbers in Java, high-precision operations become very simple, as for the two classes of objects can represent the maximum range is unclear, theoretically can represent a large number of wireless, as long as the computer memory is large enough.
These two classes are all in the java.math.* package, so you must refer to the package at the beginning of each one at a time.

Ⅰ Basic functions:
1.valueOf (parament); To convert a parameter to a developed type
such as int a=3;
BigInteger b=biginteger.valueof (a);
Then b=3;
String s= "12345";
BigInteger c=biginteger.valueof (s);
Then c=12345;

2.add (); Add large integers
BigInteger a=new BigInteger ("23");
BigInteger b=new BigInteger ("34");
A. Add (b);

3.subtract (); Subtraction
4.multiply (); Multiply
5.divide (); Divide rounding
6.remainder (); Take surplus
7.pow (); A.pow (b) =a^b
8.GCD (); Greatest common divisor
9.abs (); Absolute
10.negate (); Take the inverse number
11.mod (); A.mod (b) =a%b=a.remainder (b);
12.max (); Min ();
13.punlic int Comareto ();
14.boolean equals (); is equal
15.BigInteger Constructors:
Generally used in the following two kinds:
BigInteger (String val);
Converts the specified string to a decimal representation;
BigInteger (String val,int radix);
Converts the string representation of a BigInteger of a specified cardinality to BigInteger

Excerpted from http://blog.csdn.net/daniel_csdn/article/details/49534621

and a http://ly5633.iteye.com/blog/1218724.

Basic functions of Java large number class BigInteger and BigDecimal

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.