Here you can find the source of formatInt(int myint, int maxint)
Parameter | Description |
---|---|
myint | - is the integer to be formatted |
maxint | - is the length of the formatted string |
public static String formatInt(int myint, int maxint)
//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(); } }