2

I am trying to print the BigDecimal in the given input format,but its pre-pending a zero before decimal point.

BigDecimal bd = new BigDecimal(.356);
System.out.println(bd);

Output : 0.356

Excepted Output : .356

Madhawa Priyashantha
  • 9,427
  • 7
  • 31
  • 59
ihappyk
  • 505
  • 1
  • 5
  • 16

1 Answers1

2

Use DecimalFormat to suppress the leading zeros such as:

    import java.text.DecimalFormat;
    import java.math.*;

    BigDecimal bd = new BigDecmial(.925);
    DecimalFormat df = new DecimalFormat("#.000");
    System.out.println(df.format(bd)); // .925
doomducky
  • 53
  • 7