Java学习笔记4:大数值

Java学习笔记4:大数值

java.math包含两个可以处理任意长度数字序列数值的类:BigIntegerBigDecimal

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

注意,该类型不能使用+、-、*、/等运算符。

常用的方法如下:

类型方法名称作用解释
BigIntegeradd(BigInteger other)返回这个大整数和另一个大整数other运算的结果
BigIntegersubtract(BigInteger other)返回这个大整数和另一个大整数other运算的结果
BigIntegermultiply(BigInteger other)返回这个大整数和另一个大整数other运算的结果
BigIntegerdivide(BigInteger other)返回这个大整数和另一个大整数other运算的结果
BigIntegermod(BigInteger other)返回这个大整数和另一个大整数other取运算的结果
intcompareTo(BigInteger other)大整数与other比较大小,大于取1,等于取0,小于取-1
static BigIntegervalueOf(long x)返回值等于x的大整数
类型方法名称作用解释
BigDecimaladd(BigDecimal other)返回这个大浮点数和另一个大浮点数other运算的结果
BigDecimalsubtract(BigDecimal other)返回这个大浮点数和另一个大浮点数other运算的结果
BigDecimalmultiply(BigDecimal other)返回这个大浮点数和另一个大浮点数other运算的结果
BigDecimaldivide(BigDecimal other)返回这个大浮点数和另一个大浮点数other运算的结果
BigDecimalmod(BigDecimal other)返回这个大浮点数和另一个大浮点数other取运算的结果
intcompareTo(BigDecimal other)大浮点数与other比较大小,大于取1,等于取0,小于取-1
static BigDecimalvalueOf(long x)返回值等于x的大浮点数
static BigDecimalvalueOf(long x,int scale)返回值为x/(10^scale)的一个大浮点数
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值