Java examples for java.lang:int
Format int To String
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int val = 2; int width = 2; System.out.println(intToString(val, width)); }/*from w w w . j av a 2 s. c o m*/ static String mSpaces = " "; public static String intToString(int val, int width) { String str = new String("" + val); if (str.length() >= width) { return str; } return mSpaces.substring(0, width - str.length()) + str; } }