I have an int between 1 - 99. How do I get it to always be a double digit, ie: 01, 04, 21?
Presumably you mean to store the number in a String.
Since JDK1.5 there has been the String.format() method, which will let you do exactly what you want:
String s = String.format("%02d", someNumber);
One of the nice things about String.format() is that you can use it to build up more complex strings without resorting to lots of concatenation, resulting in much cleaner code.
String logMessage = String.format("Error processing record %d of %d: %s", recordNumber, maxRecords, error);
Try this
String.format("%02d", num)
One possible solution:
String.valueOf(number + 100).substring(1);
use number format http://download.oracle.com/javase/6/docs/api/java/text/NumberFormat.html
Using
String.format("%02d", num)
Is probably the best option.
You can't do it just using an int. You'll have to convert between Strings (for display) and back to ints (for calculations). You can use the Java Formatter to format your Strings based on the input.