How can I get an Integer to be two digits. If it's under 10 it would show 01,02, etc. I want to keep the Integer as an Integer. String.format gives a string. How can I do this with Decimalformat for ex
Decimalformat df = new Decimalformat(???);
If you want to keep the value as an int
or Integer
, there's nothing to be done here. A number doesn't have a format - it just has a value. For example, an int
isn't "in decimal" or "in hex" or "in binary" - if you write
int x = 16;
int y = 0x10;
those are the exact same values.
The idea of "padding" only makes any sense when it comes to a textual representation of the number - which is when you end up with a string.
See more on this question at Stackoverflow