Format String become xxx1, xx10 or 1****, 10*** etc

Posted by trycatch4j on Stack Overflow See other posts from Stack Overflow or by trycatch4j
Published on 2010-05-18T16:35:12Z Indexed on 2010/05/19 10:40 UTC
Read the original article Hit count: 145

Hi all,

I have following numbers : 1, 2, 3, 4, 10

But I want to print those numbers like this:

0001
0002
0003
0004
0010

I have searched in Google. the keyword is number format. But I've got nothing, I just get, format decimal such ass 1,000,000.00. I hope you can suggest me a reference or give me something to solve this problem.

Thanks

Edit, we can use NumberFormat, or String.format("%4d", somevalue); but it just for adding 0 character before integer. How If I wanna use character such as x, # or maybe whitespace. So the character become: xxxx1 xxx10 or ####1 ###10 or 1#### 10###

© Stack Overflow or respective owner

Related posts about string-manipulation

Related posts about java