java中如果位数不够,如何添加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);
...全部
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);。收起