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); System.out.println(str2);

出处:https://blog.csdn.net/u012626724/article/details/50957133/


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM