I am getting "duplicate format flag exception" on 4th line. Am I missing something in format?
String fmt = "%1$00.3f";
Object[] obj = new Object[1];
obj[0] = new Double((double) 2);
String.format(fmt,obj)
Problem is that you're repeating the flag 0
, if you want a float padded with zeros to have at least two digits in the integer part, try this:
String fmt = "%1$06.3f";
The length field (6) means: 3 digits for the fractional part + 1 digit for the dot + 2 digits for the integral part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With