比如说提供一个数字25,想输出它的四位数形式,0025,那么代码这样写:
DecimalFormat df = new DecimalFormat("0000"); String res = df.format(25);//输出 0025