Java Long Number Format format(long value)

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

Description

format

License

Open Source License

Declaration

public static String format(long value) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String[] SIZE_SUFFIXES = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };

    public static String format(long value) {
        if (value < 0)
            return "-" + format(-value);
        if (value == 0)
            return "0B";

        final int mag = (int) (Math.log10(value) / Math.log10(1024));
        final float adjustedSize = (float) value / (1L << (mag * 10));

        final String format = (mag > 2 ? "%.2f" : "%.0f") + "%s";
        return String.format(format, adjustedSize, SIZE_SUFFIXES[mag]);
    }// ww  w  .j  a  v a 2 s .c  o m
}

Related

  1. format(long numero, int numeroZeri)
  2. format(long offsetMillis)
  3. format(long s)
  4. format(long seconds)
  5. format(Long value)
  6. formatLong(long inLong, int inLen, boolean inComma, int inCommaPos)
  7. formatLong(Long number)
  8. formatLong(long val, int size)
  9. formatLong(long value)