如何以格式表示数字
001 = 1
002 = 2
003 = 3
010 = 10
020 = 20
Run Code Online (Sandbox Code Playgroud)
位数始终为3.
Joh*_*kup 11
如果要输出整数,使它们始终具有前导零,请在格式字符串中的数字位数之前使用带有零的String.format,例如:
int i = 3;
String s = String.format("%03d", i);
System.out.println(s);
Run Code Online (Sandbox Code Playgroud)
给出输出:
003
Run Code Online (Sandbox Code Playgroud)