I'm using DecimalFormat to format doubles to 2 decimal places like this:
DecimalFormat dec = new DecimalFormat("#.##");
double rawPercent = ( (double)(count.getCount().intValue()) /
(double)(total.intValue()) ) * 100.00;
double percentage = Double.valueOf(dec.format(rawPercent));
It works, but if i have a number like 20, it gives me this:
20.0
and I want this:
20.00
Any suggestions?
Try using a DecimalFormat of "0.00" instead. According to the JavaDocs, this won't strip off the extra 0s.