ITeye博客

【转】将原数据前补零,格式字符串

Jw.mac · 2013-01-07 19:31 · java · 编程语言 · Markdown

/**
  * 将原数据前补零,补后的总长度为指定的长度,以字符串的形式返回
  * @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;
 }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。