Java Integer to intToTwoDigitString(int integer)

Here you can find the source of intToTwoDigitString(int integer)

Description

Create two digit string with leading zeros from integer.

License

Open Source License

Parameter

Parameter Description
integer to convert to three digit string.

Exception

Parameter Description
IllegalArgumentException if integer do not fit in.

Return

- integer as two digit String with leading zeros.

Declaration

public static String intToTwoDigitString(int integer) 

Method Source Code

//package com.java2s;
/*/*from  ww  w .  j  a  v a  2 s  .c o  m*/
 ****************************************************************************
 *                                                                          *
 *                   (c) Copyright 2008 ABM-utvikling                       *
 *                                                                          *
 * This program is free software; you can redistribute it and/or modify it  *
 * under the terms of the GNU General Public License as published by the    *
 * Free Software Foundation; either version 2 of the License, or (at your   *
 * option) any later version.                                               *
 *                                                                          *
 * This program is distributed in the hope that it will be useful, but      *
 * WITHOUT ANY WARRANTY; without even the implied warranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
 * Public License for more details. http://www.gnu.org/licenses/gpl.html    *
 *                                                                          *
 ****************************************************************************
 */

public class Main {
    /**
     * Create two digit string with leading zeros from integer.
     * 
     * @param integer to convert to three digit string.
     * @return - integer as two digit String with leading zeros.
     * @throws IllegalArgumentException if integer do not fit in.
     */
    public static String intToTwoDigitString(int integer) {

        String number = String.valueOf(integer);
        int numberLength = number.length();

        if (numberLength == 2) {
            return number;
        } else if (numberLength == 1) {
            return "0" + number;
        }

        throw new IllegalArgumentException(
                "intToTwoDigitString: integer does not fit in, integer was: '" + integer + "'");
    }
}

Related

  1. intToTime(int time)
  2. intToTime(int value)
  3. intToTriplePlace(int i)
  4. intToTwoByte(int value, byte[] destination, int offset)
  5. intToTwoBytes(int value)
  6. intToTwoHexString(final int value)
  7. intToUByte(int i)
  8. intToULong(int signed)
  9. intToUnsigned(int signed)