Java Integer Format formatInt2(int n)

Here you can find the source of formatInt2(int n)

Description

Formats an integer to 2 digits, as used for example in time.

License

Open Source License

Declaration

public static final String formatInt2(int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  ww  w .  j  a  v  a2s. c  o  m
     * Formats an integer to 2 digits, as used for example in time.
     * I.e. a 0 gets printed as 00.
     **/
    public static final String formatInt2(int n) {
        if (n > 9) {
            return Integer.toString(n);
        }
        return "0" + n;
    }
}

Related

  1. formatInt(int value, int numDigit)
  2. formatInt(int value, int width)
  3. formatInt(String value)
  4. formatInt(String value)
  5. formatInt(String value, int defaultValue)
  6. formatInt64(long val)
  7. formatIntAsDottedOctet(int value)
  8. formatIntAsIpAddress(final int address)
  9. formatInteger(byte[] btValue, int iOffset, int iLength)