Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static String formatSize(String strSize) { try { long size = Long.parseLong(strSize); String sizePref = "B"; if (size >= 1073741824) { size = size / 1073741824; sizePref = "GB"; } else if (size >= 1048576) { size = size / 1048576; sizePref = "MB"; } else if (size >= 1024) { size = size / 1024; sizePref = "KB"; } return "Size: " + size + " " + sizePref; } catch (NumberFormatException e) { return ""; } } }