[Resolved] Add a Leading Zero to an Integer?
I want to know how to format an integer so that it always displays as two digits, so if the number is 5, it adds a leading 0 as 05. This is to display time. I tried using DecimalFormat, but it doesn't seem to be doing what I want it to, and I get errors half the time.
Any suggestions?
Re: Add a Leading Zero to an Integer?
Code:
NumberFormat f=new DecimalFormat("00");
System.out.println(f.format(5));
?
Re: Add a Leading Zero to an Integer?
I think you need to use SimpleDecimalFormat, as DecimalFormat is abstract.
Re: Add a Leading Zero to an Integer?
Quote:
Originally Posted by brown monkey
Code:
NumberFormat f=new DecimalFormat("00");
System.out.println(f.format(5));
?
This is what I came up with as well. Thank you.