I get an input from the user. I want to print it in this format:
0#.##
or
##.##
how do I do this in java?
Today I'm using:
padWithZeroRightToPeriod(product.formats[index],Float.parseFloat(currentPrice));
and
private String padWithZeroRightToPeriod(String serverFormat, float unformattedNumber) {
int nDigits = getNumberOfDigitsAfterPeriod(serverFormat);
String floatingFormat = "%4." + nDigits + "f";
String formattedPrice = String.format(floatingFormat, unformattedNumber);
return formattedPrice
}
but it converts 08.56
to 8.56
.