Here you can find the source of formatNumber(double value)
public static String formatNumber(double value)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatNumber(double value) { if (value < 1000D) return String.valueOf(value); else if (value < 1000000D) return String.valueOf(Math.round(value) / 1000D) + "K"; else if (value < 1000000000D) return String.valueOf(Math.round(value / 1000D) / 1000D) + "M"; else if (value < 1000000000000D) return String.valueOf(Math.round(value / 1000000D) / 1000D) + "B"; else/* w ww . ja v a 2s . co m*/ return String.valueOf(Math.round(value / 1000000000D) / 1000D) + "T"; } public static String formatNumber(long value) { if (value < 1000L) return String.valueOf(value); else if (value < 1000000L) return String.valueOf(Math.round(value) / 1000D) + "K"; else if (value < 1000000000L) return String.valueOf(Math.round(value / 1000L) / 1000D) + "M"; else if (value < 1000000000000L) return String.valueOf(Math.round(value / 1000000L) / 1000D) + "B"; else if (value < 1000000000000000L) return String.valueOf(Math.round(value / 1000000000L) / 1000D) + "T"; else if (value < 1000000000000000000L) return String.valueOf(Math.round(value / 1000000000000L) / 1000D) + "Quad"; else if (value <= Long.MAX_VALUE) return String.valueOf(Math.round(value / 1000000000000000L) / 1000D) + "Quin"; else return "Something is very broken!!!!"; } public static double round(double number, double multiplier) { return Math.round(number * multiplier) / multiplier; } }