Here you can find the source of leftPad(final String numStr, final int numDigits)
Parameter | Description |
---|---|
numStr | String format number |
numDigits | Number of digits field should be |
private static String leftPad(final String numStr, final int numDigits)
//package com.java2s; /*L/*from w w w . j ava2s. com*/ * Copyright RTI International * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/webgenome/LICENSE.txt for details. */ public class Main { /** * Left pad given number string with zeros. * @param numStr String format number * @param numDigits Number of digits field should be * @return Left padded numeric string */ private static String leftPad(final String numStr, final int numDigits) { StringBuffer buff = new StringBuffer(numStr); int delta = numDigits - numStr.length(); for (int i = 0; i < delta; i++) { buff.insert(0, '0'); } return buff.toString(); } }