Reputation: 550
Suppose you have:
int a = 3;
And I want to specify that the number of digits is 5. So that when I print it the output is:
00003
Thanks!
Upvotes: 3
Views: 1049
Reputation: 262534
An int
stores only the value, no formatting information. To show or preserve leading zeros you have to use a String.
System.out.println(String.format("%05d", a));
Upvotes: 11