Running this simple program:
public static void main(final String... args)
{
System.out.println(BigDecimal.ZERO.scale());
System.out.println(new BigDecimal("0").scale());
System.out.println(new BigDecimal("0.0").stripTrailingZeros().scale());
System.out.println(new BigDecimal("1.0").stripTrailingZeros().scale());
}
outputs:
0
0
1
0
My question is rather simple: why doesn't the third println
output 0
? That would seem logical...
EDIT: OK, so, this is a very old bug:
Bug Link
and in fact, it "works" for any number of zeroes: new BigDecimal("0.0000").stripTrailingZeroes().scale()
is 4!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…