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
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
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