注意:这两种方法,位数超出也会正常显示。 方法一: // result = 001 result = String.format("%0"+3+"d", 1); System.out.println("result = " + result); 方法二: // result = 001 Format fm = new DecimalFormat("000"); String result = fm.format(1); System.out.println("result = " + result);