Java Long Number Readable Format humanize(long value)

Here you can find the source of humanize(long value)

Description

humanize

License

Open Source License

Declaration

public static String humanize(long value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    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/*  w  ww  . j  ava 2  s.c o m*/
            return Long.toString((value)) + ' ';
    }

    public static String toString(Object obj) {
        return obj == null ? "" : obj.toString();
    }
}

Related

  1. getHumanReadableSize(long fileSize)
  2. getHumanReadableSize(long size, long unit, String unitName)
  3. getHumanSize(long size)
  4. getMaxHeap(String message)
  5. getTrafficString(long bytes)
  6. humanizeBytes(long bytes)
  7. humanNumber(long num)
  8. humanreadable(long bytes, boolean si)
  9. humanReadable(long memory)