Java Zero Format zeroString(int value)

Here you can find the source of zeroString(int value)

Description

If the given value is less than 10 than pad the String return with a leading "0".

License

Open Source License

Parameter

Parameter Description
value The value.

Return

The String represenation of the value, padded with a leading "0" if value < 10

Declaration

public static String zeroString(int value) 

Method Source Code

//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 &lt; 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 &lt; 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;
    }
}

Related

  1. ZeroRemover(String[] a)
  2. zeros(int n)
  3. zeros(int size)
  4. zerosInt(int len)
  5. zeroString(int length)
  6. zeroSupply(String value, int len)
  7. zeroThrough(int max)
  8. zeroToOne(float value, float min, float max)
  9. zeroToOne(long _min, long _max, long _value)