Java Byte Array to String bytesToString(long b)

Here you can find the source of bytesToString(long b)

Description

bytes To String

License

Open Source License

Declaration

public static String bytesToString(long b) 

Method Source Code

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

public class Main {
    public static String bytesToString(long b) {
        double gb = (double) b / (1024 * 1024 * 1024);
        if (gb >= 1)
            return gb >= 10 ? (int) gb + "G" : round(gb, 1) + "G";
        double mb = (double) b / (1024 * 1024);
        if (mb >= 1)
            return mb >= 10 ? (int) mb + "M" : round(mb, 1) + "M";
        double kb = (double) b / (1024);
        if (kb >= 1)
            return kb >= 10 ? (int) kb + "K" : round(kb, 1) + "K";
        return b + "";
    }//w  ww.  j a v a  2s . c o  m

    public static double round(double x, int numPlaces) {
        double scale = Math.pow(10, numPlaces);
        return Math.round(x * scale) / scale;
    }
}

Related

  1. bytesToString(final byte[] bytes)
  2. bytesToString(final byte[] data)
  3. bytesToString(int bytes)
  4. bytesToString(int bytes)
  5. bytesToString(int... bytesInt)
  6. bytesToString(long bytes)
  7. bytesToString(long bytes)
  8. bytesToString(long size)
  9. byteTo16String(byte[] bt)