Here you can find the source of zeroFill(int value, int fieldWidth)
Parameter | Description |
---|---|
value | the value |
fieldWidth | the field width |
public static String zeroFill(int value, int fieldWidth)
//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(); } }