Java Size calcSize(double s, String type, int div)

Here you can find the source of calcSize(double s, String type, int div)

Description

calc Size

License

Open Source License

Declaration

public static String calcSize(double s, String type, int div) 

Method Source Code

//package com.java2s;
/*/*from  w ww  . jav a2  s  .  c om*/
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation,
 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  
 */

import java.text.*;

public class Main {

    public static String calcSize(double s, String type, int div) {

        if (type.equals("MB")) {
            s = s / div; // kb
            s = s / div; // MB
            return NumberFormat.getNumberInstance().format(s) + " " + type;
        } else if (type.equals("KB")) {
            s = s / div; // kb
            return NumberFormat.getNumberInstance().format(s) + " " + type;
        } else if (type.equals("MBit")) {
            s *= 8;
            s = s / div; // kb
            s = s / div; // MB
            return NumberFormat.getNumberInstance().format(s) + " " + type;
        }
        return NumberFormat.getNumberInstance().format(s) + " " + type;
    }

    public static String calcSize(double s, String type) {

        return calcSize(s, type, 1024);
    }
}

Related

  1. byteSizeString(long bytes)
  2. BytesToHRSize(String len)
  3. bytesToSizeFormat(long bytes)
  4. bytesToString(long sizeInBytes)
  5. bytesToUnits(long size)
  6. createSizeFormat(Locale locale)
  7. getBytesSpecificationDescription(double sizeInBytes, String formatSpec)
  8. getByteStr(long size)
  9. getDataSize(long size)