BigDecimal 的常用方法

本文详细介绍了Java中的BigDecimal类,包括其构造函数、基本数据类型转换、数学运算、精度控制和比较方法,展示了这个用于精确浮点数运算的重要工具。
摘要由CSDN通过智能技术生成
  • BigDecimal(double val):构造一个带有小数的 BigDecimal 对象。
  • BigDecimal(String val):构造一个 BigDecimal 对象,该对象表示 val 中指定的数值。
  • double doubleValue():将 BigDecimal 转换为 double 类型。
  • float floatValue():将 BigDecimal 转换为 float 类型。
  • int intValue():将 BigDecimal 转换为 int 类型。
  • long longValue():将 BigDecimal 转换为 long 类型。
  • byte byteValue():将 BigDecimal 转换为 byte 类型。
  • short shortValue():将 BigDecimal 转换为 short 类型。
  • char charValue():将 BigDecimal 转换为 char 类型。
  • boolean booleanValue():将 BigDecimal 转换为 boolean 类型。
  • String toString():返回 BigDecimal 对象的字符串表示。
  • int compareTo(BigDecimal other):将 this 对象与 other 对象进行比较。
  • boolean equals(Object obj):比较 this 对象与 obj 对象是否相等。
  • int hashCode():返回 this 对象的哈希码。
  • void scale(int newScale):将 BigDecimal 对象的精度设置为 newScale
  • void setScale(int newScale, int roundingMode):将 BigDecimal 对象的精度设置为 newScale,并使用 roundingMode 进行四舍五入。
  • BigDecimal add(BigDecimal other):将 this 对象与 other 对象相加。
  • BigDecimal subtract(BigDecimal other):将 this 对象与 other 对象相减。
  • BigDecimal multiply(BigDecimal other):将 this 对象与 other 对象相乘。
  • BigDecimal divide(BigDecimal other, int scale, int roundingMode):将 this 对象除以 other 对象,并返回结果。scale 参数指定结果的小数点后位数,roundingMode 参数指定四舍五入模式。
  • BigDecimal mod(BigDecimal other):返回 this 对象除以 other 对象的余数。
  • BigDecimal pow(int n):将 this 对象的幂次方为 n
  • BigDecimal sqrt():返回 this 对象的平方根。
  • BigDecimal abs():返回 this 对象的绝对值。
  • BigDecimal max(BigDecimal other):返回 this 对象与 other 对象中的最大值。
  • BigDecimal min(BigDecimal other):返回 this 对象与 other 对象中的最小值。
  • void reverse():将 BigDecimal 对象的顺序反转。
  • BigDecimal shiftLeft(int n):将 this 对象的值向左移动 n 位。
  • BigDecimal shiftRight(int n):将 this 对象的值向右移动 n 位。
  • BigDecimal and(int mask):将 this 对象与 mask 按位与。
  • BigDecimal or(int mask):将 this 对象与 mask 按位或。
  • BigDecimal xor(int mask):将 this 对象与 mask 按位异或。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值