Here you can find the source of zeroString(int value)
Parameter | Description |
---|---|
value | The value. |
public static String zeroString(int value)
//package com.java2s; public class Main { /**/* w ww . j a va 2 s . c om*/ * If the given value is less than 10 than pad the String return * with a leading "0". * * @param value The value. * @return The String represenation of the value, padded with a * leading "0" if value < 10 */ public static String zeroString(int value) { return padZero(value, 2); } /** * Left pad the given value with zeros up to the number of digits * * @param value The value. * @param numDigits number of digits * @return The String represenation of the value, padded with * leading "0"-s if value < 10E(numDigits-1) */ public static String padZero(int value, int numDigits) { return padLeft(String.valueOf(value), numDigits, "0"); } /** * Pad the given string with spaces on the left up to the given length. * * @param s String to pad * @param desiredLength ending length * @return padded String */ public static String padLeft(String s, int desiredLength) { return padLeft(s, desiredLength, " "); } /** * Pad the given string with padString on the left up to the given length. * * @param s String to pad * @param desiredLength ending length * @param padString String to pad with (e.g, " ") * @return padded String */ public static String padLeft(String s, int desiredLength, String padString) { while (s.length() < desiredLength) { s = padString + s; } return s; } }