Here you can find the source of longToStringWithZeroFill(long longValue, int width)
Parameter | Description |
---|---|
longValue | The long to convert. |
width | Width of result field. |
public static String longToStringWithZeroFill(long longValue, int width)
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /** Convert long to string with left zero fill. *// w w w .j a v a 2 s . co m * @param longValue The long to convert. * @param width Width of result field. * * @return The long converted to a string * with enough leading zeros to fill * the specified field width. */ public static String longToStringWithZeroFill(long longValue, int width) { String s = new Long(longValue).toString(); if (s.length() < width) s = dupl('0', width - s.length()) + s; return s; } /** Duplicate character into string. * * @param ch The character to be duplicated. * @param n The number of duplicates desired. * * @return String containing "n" copies of "ch". * * <p> * if n <= 0, the empty string "" is returned. * </p> */ public static String dupl(char ch, int n) { if (n > 0) { StringBuffer result = new StringBuffer(n); for (int i = 0; i < n; i++) { result.append(ch); } return result.toString(); } else { return ""; } } /** Duplicate string into string. * * @param s The string to be duplicated. * @param n The number of duplicates desired. * * @return String containing "n" copies of "s". * * <p> * if n <= 0, the empty string "" is returned. * </p> */ public static String dupl(String s, int n) { if (n > 0) { StringBuffer result = new StringBuffer(n); for (int i = 0; i < n; i++) { result.append(s); } return result.toString(); } else { return ""; } } }