Here you can find the source of shortenCount(final long count)
Parameter | Description |
---|---|
count | a parameter |
public static String shortenCount(final long count)
//package com.java2s; //License from project: Open Source License public class Main { /**//ww w. ja v a 2s .co m * Changes a large number into a binary postfixed version. * For example: 10,500 -> 10.5K * * @param count * @return */ public static String shortenCount(final long count) { int unit = 1000; // Are there at least 1000? if (count < unit) { return Long.toString(count); } // Calculate the exponential int exponential = (int) (Math.log(count) / Math.log(unit)); // Get the posfix char char postfix = "KMBT".charAt(exponential - 1); return String.format("%.1f%c", (count / Math.pow(unit, exponential)), postfix); } }