Java Integer Format formatInt(int myint, int maxint)

Here you can find the source of formatInt(int myint, int maxint)

Description

public function formatInt()

License

GNU General Public License

Parameter

Parameter Description
myint - is the integer to be formatted
maxint - is the length of the formatted string

Return

String used by function formatPretty() to transform an int into a formatted string pretty much like printf %d

Declaration

public static String formatInt(int myint, int maxint) 

Method Source Code

//package com.java2s;
/*/*from w  w  w. j  a  v  a 2s  .  c  o m*/
 * Created on Apr 6, 2004
 *
 * PKR - The Protein Kinase Resource - Development Code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors and University of California.
 * These should be listed in @author doc comments.
 *
 * For more information on The Protein Kinase Resource project
 * and its aims, or to join the kinases@sdsc.edu mailing list,
 * visit the home page at:
 *
 *      http://pkr.sdsc.edu/
 *
 * This source code may be freely  distributed, provided that no
 * charge above the cost of distribution is levied, and that the
 * disclaimer below is always attached to it.
 *
 * Disclaimer:
 * The software is provided as is without any guarantees or warranty.
 * Although the author has attempted to find and correct any bugs
 * in the  free software programs,  the author is not responsible
 * for any damage or losses of any kind caused by the use or misuse
 * of the programs.
 * PKR or the author are under no obligation to provide support,
 * service, corrections, or upgrades  to the free software programs.
 *
 */

public class Main {
    /**
     * public function formatInt()
     *
     * @param myint - is the integer to be formatted
     * @param maxint - is the length of the formatted string
     *
     * @return String
     *
     * used by function formatPretty() to
     * transform an int into a formatted string
     * pretty much like printf %d
     *
     */
    public static String formatInt(int myint, int maxint) {
        Integer myInt = Integer.valueOf(myint);
        Integer maxInt = Integer.valueOf(maxint);
        int prefix = maxInt.toString().length() - myInt.toString().length();
        StringBuffer formattedInt = new StringBuffer();
        for (int i = 0; i < prefix; i++) {
            formattedInt.append(" ");
        }
        formattedInt.append(myint + " ");
        return formattedInt.toString();
    }
}

Related

  1. format(int num, int length)
  2. format(int spaces, String string)
  3. format(int ticks)
  4. formatInt(int i, int radix, int len)
  5. formatInt(int in, int precision)
  6. formatINT(int n)
  7. formatInt(int n)
  8. formatInt(int value, int length)
  9. formatInt(int value, int numDigit)