Here you can find the source of formatSpeed(float bytesPerSecond)
public static String formatSpeed(float bytesPerSecond)
//package com.java2s; public class Main { public static String formatSpeed(float bytesPerSecond) { float bitsPerSecond = bytesPerSecond * 8; int unit = 1000; if (bitsPerSecond < unit) return bitsPerSecond + " bits/sec"; int exp = (int) (Math.log(bitsPerSecond) / Math.log(unit)); String pre = String.valueOf("kmgtpe".charAt(exp - 1)); return String.format("%.1f %sB/sec", bitsPerSecond / Math.pow(unit, exp), pre); }//from w ww. j a v a2s . co m }