Java Size size(long l)

Here you can find the source of size(long l)

Description

size

License

Open Source License

Declaration

public static String size(long l) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {
    public static String size(long l) {
        String dsize = "";
        long k = l;
        double m = l / 1024.0;
        double g = l / 1048576.0;
        double t = l / 1073741824.0;

        DecimalFormat dec = new DecimalFormat("0.00");

        if (k > 1) {
            dsize = dec.format(k).concat(" KB");
        }/* ww w .  j av  a 2s  .  c  om*/

        if (m > 1) {
            dsize = dec.format(m).concat(" MB");
        }
        if (g > 1) {
            dsize = dec.format(g).concat(" GB");
        }
        if (t > 1) {
            dsize = dec.format(t).concat(" TB");
        }

        if (!dsize.isEmpty())
            return dsize;
        else
            return "Dit kon niet berekend worden er ging iets fout dit kan aan u pc liggen.";
    }
}

Related

  1. readableSize(long num)
  2. readableSize(long size)
  3. readableSize(long size)
  4. readableSize(long size, DecimalFormat format)
  5. renderNumber(int n, int size)
  6. size2human(long size)
  7. sizeRenderer(String value)
  8. stringToSize(String sizeString)
  9. toByte(String size)