Java examples for java.lang:double Format
get Formatted Amount in K or M
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int j = 2; System.out.println(getFormattedAmount(j)); }/*from www . j a va 2s . co m*/ public static final String getFormattedAmount(int j) { if (j >= 1 && j < 99999) return String.valueOf(j); else if (j >= 100000 && j < 9999999) return j / 1000 + "K"; else if (j >= 10000000 && j < Integer.MAX_VALUE) return j / 1000000 + "M"; else return "?"; } }