If you need to represent fixed point Numbers, such as dollars and cents, use BigDecimal instead.
如果需要表示定点数(譬如,几美元和几美分),则使用BigDecimal。
Because BigDecimal objects are immutable, each of these methods produces a new BigDecimal object.
由于BigDecimal对象是不可变的,这些方法中的每一个都会产生新的BigDecimal对象。
For this reason, BigDecimal gives you explicit control over rounding when performing division operations.
出于这个原因,在进行除法运算时,BigDecimal可以让您显式地控制舍入。
If you are looking to represent exact quantities such as monetary amounts, BigDecimal is well-suited to the task.
如果您正在寻找一种能精确表示如货币量这样的数值,则BigDecimal可以很好地胜任该任务。
Of course, if you really do need the extra precision, then you'll need to pick a data type with more precision, such as a double or a BigDecimal.
当然,如果一定需要额外的精度,则可以选择具有高精度的数据类型,比如double或BigDecimal。
BigDecimal is a standard class, with no special support in the compiler, to represent arbitrary-precision decimal Numbers and perform arithmetic on them.
BigDecimal是标准的类,在编译器中不需要特殊支持,它可以表示任意精度的小数,并对它们进行计算。
Internally, BigDecimal is represented as an arbitrary-precision unscaled value and a scale factor, which represents how many places to move the decimal point left to obtain the scaled value.
在内部,可以用任意精度任何范围的值和一个换算因子来表示BigDecimal,换算因子表示左移小数点多少位,从而得到所期望范围内的值。
Internally, BigDecimal is represented as an arbitrary-precision unscaled value and a scale factor, which represents how many places to move the decimal point left to obtain the scaled value.
在内部,可以用任意精度任何范围的值和一个换算因子来表示BigDecimal,换算因子表示左移小数点多少位,从而得到所期望范围内的值。
应用推荐