Java Long Number Readable Format humanReadable(long number)

Here you can find the source of humanReadable(long number)

Description

human Readable

License

Apache License

Declaration

public static String humanReadable(long number) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    public static String humanReadable(long number) {
        long absNumber = Math.abs(number);
        double result = number;
        String suffix = "";
        if (absNumber < 1024L) {
            return String.valueOf(number);
        }/*from   w w  w  .  j av a2s  . c  om*/
        if (absNumber < 1048576L) {
            result = number / 1024.0D;
            suffix = "k";
        } else if (absNumber < 1073741824L) {
            result = number / 1048576.0D;
            suffix = "m";
        } else {
            result = number / 1073741824.0D;
            suffix = "g";
        }
        return new DecimalFormat("0.0").format(result) + suffix;
    }
}

Related

  1. humanize(long value)
  2. humanizeBytes(long bytes)
  3. humanNumber(long num)
  4. humanreadable(long bytes, boolean si)
  5. humanReadable(long memory)
  6. humanReadableByteCount(final long bytes)
  7. humanReadableByteCount(final long bytes, final boolean si)
  8. humanReadableByteCount(long bytes)
  9. humanReadableByteCount(Long bytes, boolean decimal)