I want to format 4-digit numbers with left padded zeros and 5-digit numbers with no leading zeros so when e.g:
I tried String.format("%05d", Integer.parseInt(something));
but when I format 124, I get 00124
Try %04d
instead:
0
indicates what you're using to pad;4
is the width of the number (you had 5
before);d
represents an integer (incl. byte, short, int, long, bigint).String.format("%04d", Integer.parseInt(something));