开发者

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

开发者 https://www.devze.com 2023-01-22 00:52 出处:网络
I need to format numbers in a way that they should be preceded with zeros to contain开发者_运维百科 5 digits.

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.


%05d should do it I believe


int a=123;   
System.out.println(String.format("%05d",a));
0

精彩评论

暂无评论...
验证码 换一张
取 消