Utils { public static String humanize(long value) { if (value < 0) { return '-' + humanize(-value); } else if (value > 1000000000000000000L) { return Double.toString( (value + 500000000000000L) / 1000000000000000L * 1000000000000000L / 1000000000000000000.0) + 'E'; } else if (value > 100000000000000000L) { return Double.toString( (value + 50000000000000L) / 100000000000000L * 100000000000000L / 1000000000000000.0) + 'P'; } else if (value > 10000000000000000L) { return Double .toString((value + 5000000000000L) / 10000000000000L * 10000000000000L / 1000000000000000.0) + 'P'; } else if (value > 1000000000000000L) { return Double .toString((value + 500000000000L) / 1000000000000L * 1000000000000L / 1000000000000000.0) + 'P'; } else if (value > 100000000000000L) { return Double.toString((value + 50000000000L) / 100000000000L * 100000000000L / 1000000000000.0) + 'T'; } else if (value > 10000000000000L) { return Double.toString((value + 5000000000L) / 10000000000L * 10000000000L / 1000000000000.0) + 'T'; } else if (value > 1000000000000L) { return Double.toString((value + 500000000) / 1000000000 * 1000000000 / 1000000000000.0) + 'T'; } else if (value > 100000000000L) { return Double.toString((value + 50000000) / 100000000 * 100000000 / 1000000000.0) + 'G'; } else if (value > 10000000000L) { return Double.toString((value + 5000000) / 10000000 * 10000000 / 1000000000.0) + 'G'; } else if (value > 1000000000) { return Double.toString((value + 500000) / 1000000 * 1000000 / 1000000000.0) + 'G'; } else if (value > 100000000) { return Double.toString((value + 50000) / 100000 * 100000 / 1000000.0) + 'M'; } else if (value > 10000000) { return Double.toString((value + 5000) / 10000 * 10000 / 1000000.0) + 'M'; } else if (value > 1000000) { return Double.toString((value + 500) / 1000 * 1000 / 1000000.0) + 'M'; } else if (value > 100000) { return Double.toString((value + 50) / 100 * 100 / 1000.0) + 'K'; } else if (value > 10000) { return Double.toString((value + 5) / 10 * 10 / 1000.0) + 'K'; } else if (value > 1000) { return Double.toString(value / 1000.0) + 'K'; } else { return Long.toString(value) + ' '; } } private  Utils(); static Character[] toObjectArray(char[] array); static Integer[] toObjectArray(int[] array); static Long[] toObjectArray(long[] array); static Short[] toObjectArray(short[] array); static Byte[] toObjectArray(byte[] array); static Float[] toObjectArray(float[] array); static Double[] toObjectArray(double[] array); static Boolean[] toObjectArray(boolean[] array); @SuppressWarnings({"unchecked"}) static T[] arrayOf(T firstElement, T... moreElements); @SuppressWarnings({"unchecked"}) static T[] arrayOf(T firstElement, T secondElement, T... moreElements); @SuppressWarnings({"unchecked"}) static T[] arrayOf(T[] firstElements, T lastElement); static String toString(Object obj); static boolean equal(T a, T b); static List<Class<?>> getTypeArguments(Class<?> base, Class<?> implementation); static Class<?> getClass(Type type); static boolean isBoxedType(Class<?> primitive, Class<?> boxed); static Constructor findConstructor(Class<?> type, Object[] args); static String humanize(long value); static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY; static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY; static final Long[] EMPTY_LONG_OBJECT_ARRAY; static final Short[] EMPTY_SHORT_OBJECT_ARRAY; static final Byte[] EMPTY_BYTE_OBJECT_ARRAY; static final Float[] EMPTY_FLOAT_OBJECT_ARRAY; static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY; static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY; }
@Test public void testHumanize() { assertEquals(humanize(0), "0 "); assertEquals(humanize(1), "1 "); assertEquals(humanize(12), "12 "); assertEquals(humanize(123), "123 "); assertEquals(humanize(1234), "1.234K"); assertEquals(humanize(1200), "1.2K"); assertEquals(humanize(12345), "12.35K"); assertEquals(humanize(123456), "123.5K"); assertEquals(humanize(1234567), "1.235M"); assertEquals(humanize(12345678), "12.35M"); assertEquals(humanize(123456789), "123.5M"); assertEquals(humanize(1234567890), "1.235G"); assertEquals(humanize(12345678901L), "12.35G"); assertEquals(humanize(123456789012L), "123.5G"); assertEquals(humanize(1234567890123L), "1.235T"); assertEquals(humanize(12345678901234L), "12.35T"); assertEquals(humanize(123456789012345L), "123.5T"); assertEquals(humanize(1234567890123456L), "1.235P"); assertEquals(humanize(12345678901234567L), "12.35P"); assertEquals(humanize(123456789012345678L), "123.5P"); assertEquals(humanize(1234567890123456789L), "1.235E"); }