Here you can find the source of formatInt(int in, int precision)
Parameter | Description |
---|---|
in | int to convert |
public static String formatInt(int in, int precision)
//package com.java2s; //License from project: Apache License public class Main { /**/*ww w . j a v a2 s . c o m*/ * convert a double into a String with a given precision * default double formatting is not very pretty * @param in int to convert * @param int positive precision * @return non-null formatted string */ public static String formatInt(int in, int precision) { String ret = Integer.toString(in); if (ret.length() > precision) throw new IllegalArgumentException("Cannot write " + in + " in " + precision + " digits"); while (ret.length() < precision) ret = "0" + ret; return (ret); } /**{ method @name toString @function convert a char to a string @param c the char @return the String }*/ public static String toString(char c) { StringBuffer s = new StringBuffer(); s.append(c); return (s.toString()); } }