---
title: "【转】将原数据前补零，格式字符串"
author: "Jw.mac"
date: "2013-01-07T19:31:09Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-04-14T11:41:22Z"
id: 1765677
url: "https://jw-mac.iteye.com/blog/1765677"
---

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