
| No. | 方法 | 類型 | 描述 |
| 1 | public BigInteger(String val) | 構(gòu)造 | 將一個字符串變?yōu)锽igInteger類型的數(shù)據(jù) |
| 2 | public BigInteger add(BigInteger val) | 普通 | 加法 |
| 3 | public BigInteger subtract(BigInteger val) | 普通 | 減法 |
| 4 | public BigInteger multiply(BigInteger val) | 普通 | 乘法 |
| 5 | public BigInteger divide(BigInteger val) | 普通 | 除法 |
| 6 | public BigInteger max(BigInteger val) | 普通 | 返回兩個大數(shù)字中的最大值 |
| 7 | public BigInteger min(BigInteger val) | 普通 | 返回兩個大數(shù)字中的最小值 |
| 8 | public BigInteger[] divideAndRemainder(BigInteger val) | 普通 | 除法操作,數(shù)組的第一個元素為除法的商,第二個元素為除法的余數(shù) |
package com.pb.demo1;import java.math.BigInteger;public class BigIntegerDemo { public static void main(String[] args) { BigInteger bi1=new BigInteger("123456789"); BigInteger bi2=new BigInteger("987654321"); System.out.結(jié)果:
加法操作:1111111110減法操作:864197532乘法操作:121932631112635269除法操作:8最大數(shù):987654321最小數(shù):123456789商是:8;余數(shù)是:9
三、使用BigDecimal指定小數(shù)的保留位數(shù)對于不需要任何準確計算精度的程序可以直接使用float或double完成,但是如果需要精確計算的結(jié)果,則必須使用BigDecimal類。| No. | 方法 | 類型 | 描述 |
| 1 | public BigDecimal(double val) | 構(gòu)造 | 將double表示形式轉(zhuǎn)換為BigDecimal |
| 2 | public BigDecimal(int val) | 構(gòu)造 | 將int表示形式轉(zhuǎn)換為BigDecimal |
| 3 | public BigDecimal(String val) | 構(gòu)造 | 將字符串表示形式轉(zhuǎn)換為BigDecimal |
| 4 | public BigDecimal add(BigDecimal augend) | 普通 | 加法 |
| 5 | public BigDecimal subtract(BigDecimal subtrahend) | 普通 | 減法 |
| 6 | public BigDecimal multiply(BigDecimal multiplicand) | 普通 | 乘法 |
| 7 | public BigDecimal divide(BigDecimal divisor) | 普通 | 除法 |
新聞熱點
疑難解答