int转String 使用0来填充长度

import java.text.DecimalFormat;
//(1)、如果数字1是字符串,如下处理:
String str1=”1”;
DecimalFormat df=new DecimalFormat(“0000”);
String str2=df.format(Integer.parseInt(str1));
System.out.println(str2);
//(2)、如果数字1是整型,如下处理:
int str1=1;
DecimalFormat df=new DecimalFormat(“0000”);
String str2=df.format(str1);
System.out.println(str2);

简便的写法
String str=String.format(“%05d”,22);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章