Prepend to Integer

Hi. I have an Integer which I need to make sure is composed of 10 numbers. If it has less e.g. 14288 I need to prepend zeros to it until it has 10 numbers e.g.0000014288.thanks
[197 byte] By [vik1491a] at [2007-11-27 6:01:31]
# 1
You can use StringBuffer and cast when necessary.
totua at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 2

> You can use StringBuffer and cast when necessary.

Um, ok - that was kind of random.

To the OP - try this:DecimalFormat fmt = new DecimalFormat("0000000000");

System.out.println(" 0 = ["+fmt.format(0L)+"]");

System.out.println("12345 = ["+fmt.format(12345)+"]");

System.out.println("1234567890 = ["+fmt.format(1234567890)+"]");

Grant

ggaineya at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 3
thanks ggainey
vik1491a at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 4
so how do I get the number of characters in th Integer?
vik1491a at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 5
Use String.valueOf(originalInt) to get it as a String, then take the String's length.
hunter9000a at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 6
is it possible to have a java Integer with 11 characters. i have just got a compiler error when trying to creating a 11 digit Integer
vik1491a at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 7
> is it possible to have a java Integer with 11> characters. i have just got a compiler error when> trying to creating a 11 digit Integer http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.lang.Integer.MAX_VALUE
cotton.ma at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 8
1,247,000,000 + change is the largest 32 bit integer.
corlettka at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 9
If you need numbers that are bigger than MAX_INT, then a) use long instead, or b) look at BigInteger.G
ggaineya at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...
# 10
Or work with Strings. It's not clear if you are using an numerical properties, like adding the buggers.
Hippolytea at 2007-7-12 16:41:33 > top of Java-index,Java Essentials,New To Java...