Java番外篇4——BigInteger与BigDecimal

Java番外篇4——BigInteger与BigDecimal

为了解决大数运算的问题

  • 操作整型:BigInteger
  • 操作小数:BigDecimal

1、BigInteger

方法声明功能介绍
public BigInteger abs()返回大整数的绝对值
public BigInteger add(BigInteger val)返回两个大整数的和
public BigInteger and(BigInteger val)返回两个大整数的按位与的结果
public BigInteger andNot(BigInteger val)返回两个大整数与非的结果
public BigInteger divide(BigInteger val)返回两个大整数的商
public BigInteger[] divideAndRemainder(BigInteger val)返回两个大整数的商和余数
public double doubleValue()返回大整数的double类型的值
public float floatValue()返回大整数的float类型的值
public BigInteger gcd(BigInteger val)返回大整数的最大公约数
public int intValue()返回大整数的整型值
public long longValue()返回大整数的long型值
public BigInteger max(BigInteger val)返回两个大整数的最大者
public BigInteger min(BigInteger val)返回两个大整数的最小者
public BigInteger mod(BigInteger val)用当前大整数对val求模
public BigInteger multiply(BigInteger val)返回两个大整数的积
public BigInteger negate()返回当前大整数的相反数
public BigInteger not()返回当前大整数的非
public BigInteger or(BigInteger val)返回两个大整数的按位或
public BigInteger pow(int exponent)返回当前大整数的exponent次方
public BigInteger remainder(BigInteger val)返回当前大整数除以val的余数
public BigInteger leftShift(int n)将当前大整数左移n位后返回
public BigInteger rightShift(int n)将当前大整数右移n位后返回
public BigInteger subtract(BigInteger val)返回两个大整数相减的结果
public byte[] toByteArray(BigInteger val)将大整数转换成二进制反码保存在byte数组中
public String toString()将当前大整数转换成十进制的字符串形式
public BigInteger xor(BigInteger val)返回两个大整数的异或

2、BigDecimal

方法声明功能介绍
BigDecimal abs()返回大浮点数的绝对值
BigDecimal negate()返回大浮点数的相反数
BigDecimal add(BigDecimal augend)返回两个大浮点数的和
BigDecimal subtract(BigDecimal subtrahend)返回两个大浮点数的差
BigDecimal multiply(BigDecimal multiplicand)返回两个大浮点数的积
BigDecimal divide(BigDecimal divisor)返回两个大浮点数的商
BigDecimal[] divideAndRemainder(BigDecimal divisor)返回两个大浮点数的商和余数
double doubleValue()将此BigDecimal转换为double
float floatValue()将此BigDecimal转换为 float
int intValue()将此BigDecimal转换为int
long longValue()将此BigDecimal转换为 long
BigDecimal divideToIntegralValue(BigDecimal divisor)返回一个BigDecimal ,它的值是BigDecimal的整数部分
BigDecimal max(BigDecimal val)返回两个大浮点数较大的数字
BigDecimal min(BigDecimal val)返回两个大浮点数较大的数字
BigDecimal movePointLeft(int n)将当前大浮点数左移n位后返回
BigDecimal movePointRight(int n)将当前大浮点数右移n位后返回
BigDecimal remainder(BigDecimal divisor)返回两个大浮点数的商的余数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

眼眸流转

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值