Java examples for java.lang:int Format
Takes in an integer, and returns a String that adds commas to the appropriate locations within the number.
//package com.java2s; import java.text.DecimalFormat; public class Main { public static void main(String[] argv) { int number = 42; System.out.println(formatNumber(number)); }//from w w w .j a v a 2 s . c om /** * Takes in an integer, * * @number, and returns a String that adds commas to the appropriate locations within the number. * @param number * @return */ public static String formatNumber(int number) { DecimalFormat formatter = new DecimalFormat("#,###"); return formatter.format(number); } }