Here you can find the source of getSizeInKB(String size)
public static String getSizeInKB(String size) throws NumberFormatException
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static DecimalFormat fFileSize = new DecimalFormat("#.000"); public static String getSizeInKB(String size) throws NumberFormatException { if (size.indexOf("-") != -1 || size.equals("0")) return "0"; String s = size.substring(0, size.length() - 1); double ds = 0; try {// w w w .jav a2s . c o m ds = Double.valueOf(s); } catch (NumberFormatException e) { System.out.println("NFE getSizeInKB str: " + size); throw e; } String u = size.substring(size.length() - 1); int sw = -1; if (u.equalsIgnoreCase("B")) sw = 0; if (u.equalsIgnoreCase("M")) sw = 1; else if (u.equalsIgnoreCase("G")) sw = 2; switch (sw) { case 0: ds = ds / 1000; break; case 1: ds = ds * 1000; break; case 2: ds = ds * 1000000; break; default: break; } return fFileSize.format(ds); } }