java.math.BigDecimal
一、定义
不可变的、任意精度的有符号十进制数。表示的数字的值BigDecimal是(unscaledValue × 10^-scale )。
BigDecimal类使用户可以完全控制舍入行为。如果没有指定取整方式,无法表示准确的结果,则抛出异常;否则,可以通过MathContext操作提供适当的对象来执行所选精度和舍入模式的计算。(使用RoundingMode的枚举值控制舍入)
两种控制位数的方式:缩放/舍入操作(setScalend round);其值大约(或完全)等于操作数的值,但其比例或精度是指定值(也就是说,它们增加或减少存储数字的精度,而对其值的影响最小);小数点移动操作(movePointLeft和movePointRight):通过将小数点沿指定方向移动指定距离操作数
二、构造函数
Constructor | Description |
---|---|
BigDecimal(BinInteger val) | Translates a BigInteger into a BigDecimal |
BigDecimal(BigInteger unscaledVal, int scale) | Translates a BigInteger unscaled value and an int scale into a BigDecimal |
BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) | TTranslates a BigInteger unscaled value and an int scale into a BigDecimal, with rounding according to the context settings |
BigDecimal(BigInteger val, MathContext mc) | Translates a BigInteger into a BigDecimal rounding according to the context settings |
BigDecimal(char[] in) | Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor |
BigDecimal(char[] in, int offset, int len) | Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor, |