Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What formatter pattern should I use to get '00123', '00001' strings from numbers '123' and '1' correspondingly?

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.

like image 805
Roman Avatar asked Dec 06 '22 01:12

Roman


2 Answers

%05d should do it I believe

like image 117
tim_yates Avatar answered Dec 07 '22 22:12

tim_yates


int a=123;   
System.out.println(String.format("%05d",a));
like image 45
jmj Avatar answered Dec 07 '22 22:12

jmj