Java Zero Format zeroFill(int value, int fieldWidth)

Here you can find the source of zeroFill(int value, int fieldWidth)

Description

Returns a zero-filled string.

License

Open Source License

Parameter

Parameter Description
value the value
fieldWidth the field width

Return

the zero filled string

Declaration

public static String zeroFill(int value, int fieldWidth) 

Method Source Code

//package com.java2s;
/*/*from   w  ww .  j av a  2s  . c o  m*/
 * Copyright (c) 2015 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    /** The zero ("0") character as a string. */
    public static final String ZERO = "0";

    /**
     * Returns a zero-filled string.  For example:
     * <pre>
     * StringUtils.zeroFill(45, 6);
     * </pre>
     * returns the string {@code "000045"}.
     *
     * @param value the value
     * @param fieldWidth the field width
     * @return the zero filled string
     */
    public static String zeroFill(int value, int fieldWidth) {
        StringBuilder buf = new StringBuilder();
        buf.append(value);
        while (buf.length() < fieldWidth) {
            buf.insert(0, ZERO);
        }
        return buf.toString();
    }
}

Related

  1. zeroEsquerda(String s1, int tamString)
  2. zeroExtend(long value, int inputBits)
  3. zeroFill(float[] array)
  4. zeroFill(int iv, int len)
  5. zeroFill(int num, int size, String character)
  6. zerofill(int x, int desiredWidth)
  7. zeroFillString(String originalString, int numZeros)
  8. zeroFormat(Integer source)
  9. zeroFormattedStr(int number, int length)