JAVA大数BigInteger与BigDecimal

时间:2022-09-03 16:12:13

BigInteger类实现了任意精度的整数运算,BigDecimal实现了任意精度的浮点数运算。

 

使用静态的valueof方法可以将普通的数值转换为大数值

BigInteger a = BigInteger.valueof(100);

 

API java.math.BigInteger

BigIntger add(BigInteger other)        加

BigIntger subtract(BigInteger other)   减

BigIntger multiply(BigInteger other)   乘

BigIntger divide(BigInteger other)     除

BigIntger mod(BigInteger other)       取余

 

Int compareTo(BigInteger other)判等,相等返回0,小于返回负数,大于返回正数

 

API java.math.BigDecimal

BigDecimal add(BigDecimal other)        加

BigDecimal subtract(BigDecimal other)   减

BigDecimal multiply(BigDecimal other)   乘

BigDecimal divide(BigDecimal other)     除