Skip to content

Commit 463f633

Browse files
Create how-can-i-pad-an-integers-with-zeros-on-the-left.md
1 parent ae67302 commit 463f633

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 如何用0向左补齐一个整数?
2+
3+
## 问题
4+
5+
在Java中如何把一个整数转化为字符串并且用0向左补齐呢?
6+
7+
我基本上是希望把一个不大于9999的整数用0补齐 (比如说1=“0001”)。
8+
9+
## 解答
10+
11+
String.format("%05d", yournumber);
12+
13+
可以将一个五位数用0补齐。
14+
15+
16+
https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
17+
18+
Stackoverflow链接:http://stackoverflow.com/questions/473282/how-can-i-pad-an-integers-with-zeros-on-the-left

0 commit comments

Comments
 (0)