Java Long Number Format format(long mem)

Here you can find the source of format(long mem)

Description

format

License

Apache License

Declaration

private static String format(long mem) 

Method Source Code

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

public class Main {
    private static String format(long mem) {
        double dMem = mem;

        String[] units = new String[] { "", "KB", "MB", "GB" };
        for (String unit : units) {
            if (dMem < 1024)
                return String.format("%.1f %s", dMem, unit);

            dMem /= 1024;//from  w  w w  .  ja v a2 s . co  m
        }

        return String.format("%.1f %s", dMem * 1024, units[units.length - 1]);
    }
}

Related

  1. comma(long n)
  2. format(final long number, final int length)
  3. format(final long value, final long divider, final String unit)
  4. format(final long value, final long divider, final String unit)
  5. format(long bytes)
  6. format(long milliseconds)
  7. format(long ms)
  8. format(long numero, int numeroZeri)
  9. format(long offsetMillis)