本文介绍了澄清BigDecimal.stripTrailingZeroes()的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下面的代码显示的是0.00而不是0?

Why the following code prints 0.00 and not 0?

BigDecimal big = new BigDecimal("0.00");
big = big.stripTrailingZeros();
System.out.println(big.toPlainString());

以下是stripTrailingZeroes的文档:

The following is the documentation for stripTrailingZeroes:

推荐答案

它将去除内部表示形式[6000,1]的尾随零,并相应地调整小数位数1 -> -2.内部表示形式在某种程度上也与最终的打印输出无关,最终的打印输出还受格式,舍入和区域设置的影响.

It strips the trailing zeroes of the internal representation [6000,1] and adapts the scale accordingly 1 -> -2. The internal representation is also somewhat independent of the final print-out which is also affected by format, rounding and locale.

这篇关于澄清BigDecimal.stripTrailingZeroes()的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:55
查看更多