 <p>Here's my solution to make it a little more generic:</p> <pre><code>private static final String[] magnitudes = new String[] {"", "K", "M"}; public static String shortenNumber(final Integer num) { if (num == null || num == 0) return "0"; float res = num; int i = 0; for (; i &lt; magnitudes.length; i++) { final float sm = res / 1000; if (sm &lt; 1) break; res = sm; } // don't use fractions if we don't have to return ( (res % (int) res &lt; 0.1) ? String.format("%d", (int)res) : String.format("%.1f", res) ) + magnitudes[i]; } </code></pre>