Java Long Number Readable Format humanNumber(long num)

Here you can find the source of humanNumber(long num)

Description

human Number

License

Open Source License

Declaration

public static String humanNumber(long num) 

Method Source Code

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

public class Main {
    public static String humanNumber(long num) {
        StringBuilder msg = new StringBuilder();
        if (num >= 0) {
            int mag = 0;
            while (num >= 1000) {
                num = num / 10;/*from   w w w . jav a 2s . c  o m*/
                mag++;
            }
            char[] oMag = { 'K', 'M', 'G' };
            if (mag > 0)
                msg.append(oMag[(mag - 1) / 3]);
            msg.insert(0, num);
            // and now the dot
            if (mag % 3 != 0)
                msg.insert(mag % 3, ".");
        }
        return msg.toString();
    }
}

Related

  1. getHumanSize(long size)
  2. getMaxHeap(String message)
  3. getTrafficString(long bytes)
  4. humanize(long value)
  5. humanizeBytes(long bytes)
  6. humanreadable(long bytes, boolean si)
  7. humanReadable(long memory)
  8. humanReadable(long number)
  9. humanReadableByteCount(final long bytes)