Here you can find the source of calcSize(double s, String type, int div)
public static String calcSize(double s, String type, int div)
//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); } }