ITPub博客

首页 > 应用开发 > Java > java在数字前面自动补零的方法

java在数字前面自动补零的方法

Java 作者:小梁124 时间:2014-12-29 16:54:24 0 删除 编辑

  /**

  * 将元数据前补零,补后的总长度为指定的长度,以字符串的形式返回

  * @param sourceDate

  * @param formatLength

  * @return 重组后的数据

  */

  public static String frontCompWithZore(int sourceDate,int formatLength)

  {

  /*

  * 0 指前面补充零

  * formatLength 字符总长度为 formatLength

  * d 代表为正数。

  */

  String newString = String.format("%0"+formatLength+"d", sourceDate);

  return newString;

  }

文章来源:http://www.mfqyw.com/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29870867/viewspace-1384004/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-09-11

  • 博文量
    71
  • 访问量
    214129