Java Long Number Readable Format toMB(long bytes)

Here you can find the source of toMB(long bytes)

Description

to MB

License

Open Source License

Declaration

public static String toMB(long bytes) 

Method Source Code

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

public class Main {
    public static String toMB(long bytes) {
        if (bytes < 0) {
            return "n/a";
        }//from w  w  w  .  j a  va2s.c  o m
        if (bytes > 1024 * 1024 * 1024) {
            return "" + (bytes / 1024 / 1024 / 1024) + "G";
        } else if (bytes > 1024 * 1024) {
            return "" + (bytes / 1024 / 1024) + "M";
        } else if (bytes > 1024) {
            return "" + (bytes / 1024) + "K";
        } else {
            return "" + bytes + "B";
        }

    }
}

Related

  1. toHumanReadableSize(long bytes)
  2. toHumanSize(long bytes)
  3. toKilobytes(long bytes)
  4. toLocalizedInteger(long value)
  5. toMB(long b)
  6. toReadableBytes(long bytes)
  7. toReadableNumber(long number)
  8. toStringLong(long id)