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
按位异或。
BigDecimal 的常用方法
最新推荐文章于 2024-05-30 17:46:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)