Here you can find the source of zeropad(final int num, final int size)
Parameter | Description |
---|---|
num | a parameter |
size | a parameter |
private static String zeropad(final int num, final int size)
//package com.java2s; /*/*w ww . j av a 2 s .co m*/ * Copyright (c) 2006 Stephan D. Cote' - All rights reserved. * * This program and the accompanying materials are made available under the * terms of the MIT License which accompanies this distribution, and is * available at http://creativecommons.org/licenses/MIT/ * * Contributors: * Stephan D. Cote * - Initial concept and implementation */ public class Main { /** * Method zeropad * * @param num * @param size */ private static String zeropad(final int num, final int size) { final String value = Integer.toString(num); if (value.length() >= size) { return value; } final StringBuffer buf = new StringBuffer(size); for (int i = 0; i++ < (size - value.length()); buf.append('0')) { ; } buf.append(value); return buf.toString(); } }