Tuesday, 10 September 2013

Java : Removing zeros after decimal point in BigDecimal

Java : Removing zeros after decimal point in BigDecimal

I have a program like this ,
BigDecimal bd = new BigDecimal(23.086);
Bigdecimal bd1= new BigDecimal(0.000);
bd = bd.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
bd1 = bd1.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
System.out.println("bd value::"+ bd);
System.out.println("bd1 value::"+ bd1);
I get the following output: 23.09 for bd and 0.00 for bd1,
But i want bd1 as 0 not as 0.00.
Am i applying the methods correctly?

No comments:

Post a Comment