Java – how do I format an integer as a string of four zeros?
•
Java
I try to do something similar in Java (eclipse indigo):
input - 16 (integer); Output - "0016" ; input - 201 (integer); Output - "0201" ; intput - 1716 (integer); Output - "1716" ;
In VB Net, I can use:
dim num as integer dim str as string str = Format(num,"0000")
How can I do the same thing in Java? Thank you in advance
Solution
I will also choose string#format () as the answer to MRE, but you can also do this:
new DecimalFormat("0000").format(number);
Please check here for more details
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码