Here you can find the source of formatSpeed(int speed, String format)
public static String formatSpeed(int speed, String format)
//package com.java2s; public class Main { public static String formatSpeed(float data) { return formatSpeed(data, "#0.00"); }/* ww w .j a va 2 s .c om*/ public static String formatSpeed(float data, String format) { java.text.DecimalFormat df = new java.text.DecimalFormat(format); if (data < 0) return "0B/s"; if (data < 1000.0) { if (data == (int) data) { df = new java.text.DecimalFormat("#0"); } return df.format(data) + "KB/s"; } if (data < (1000f * 1024.0)) return df.format(data / 1024) + "MB/s"; if (data < (1000 * 1024 * 1024.0)) return df.format(data / (1024 * 1024.0)) + "GB/s"; return df.format(data / (1024 * 1024 * 1024.0)) + "GB/s"; } public static String formatSpeed(int speed, String format) { java.text.DecimalFormat df = new java.text.DecimalFormat(format); if (speed < 0) return "0B/s"; if (speed < 1000) { return speed + "B/s"; } if (speed < 1000f * 1024.0) return df.format(speed / 1024) + "KB/s"; return df.format(speed / (1024 * 1024.0)) + "MB/s"; } }