Java Integer to String intToString(int theValue, int nDigits)

Here you can find the source of intToString(int theValue, int nDigits)

Description

Convert a positive int to a String with at least n digits, padding with leading zeroes.

License

Open Source License

Parameter

Parameter Description
theValue the int to be converted.
nDigits the number of digits to return.

Return

the converted value.

Declaration

public static String intToString(int theValue, int nDigits) 

Method Source Code

//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2005 by the Radiological Society of North America
*
*  This source software is released under the terms of the
*  RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
*----------------------------------------------------------------*/

public class Main {
    /**//from  w  ww .j  a  v a2  s. c  o m
     * Convert a positive int to a String with at least n digits,
     * padding with leading zeroes.
     * @param theValue the int to be converted.
     * @param nDigits the number of digits to return.
     * @return the converted value.
     */
    public static String intToString(int theValue, int nDigits) {
        String s = Integer.toString(theValue);
        int k = nDigits - s.length();
        for (int i = 0; i < k; i++)
            s = "0" + s;
        return s;
    }
}

Related

  1. intToString(int i)
  2. intToString(int i)
  3. intToString(int i)
  4. intToString(int integer)
  5. intToString(int n)
  6. intToString(int val, int width)
  7. intToString(int value)
  8. IntToString(int value)
  9. intToString(int value, int nChars)