views:

37

answers:

2

I need to format numbers in a way that they should be preceded with zeros to contain 5 digits.

I don't get how to create patterns for java formatter.

I tried %4d but it doesn't adds zeros.

+3  A: 

%05d should do it I believe

tim_yates
Yeap, it works!
Roman
Cool :-) The best list of formatting examples I can find is here: http://www.java2s.com/Tutorial/Java/0120__Development/0200__printf-Method.htm
tim_yates
+2  A: 
int a=123;   
System.out.println(String.format("%05d",a));
org.life.java