How do you left pad an int with zeros when converting to a String in java?
int
String
I\'m basically looking to pad out integers up to 9999
9999
Try this one:
import java.text.DecimalFormat; DecimalFormat df = new DecimalFormat("0000"); String c = df.format(9); // Output: 0009 String a = df.format(99); // Output: 0099 String b = df.format(999); // Output: 0999