Here you can find the source of formatSpeedValue(float speed)
public static String formatSpeedValue(float speed)
//package com.java2s; public class Main { public static String formatSpeedValue(float speed) { java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00"); String str = ""; if (speed >= 0 && speed < 1024.0) { df = new java.text.DecimalFormat("#0"); str = df.format(speed) + "KB/s"; } else if (speed >= 1024 && speed < (1024 * 1024.0)) { str = df.format(speed / 1024) + "MB/s"; } else if (speed >= (1024 * 1024) && speed < (1024 * 1024 * 1024.0)) { str = df.format(speed / (1024 * 1024.0)) + "GB/s"; } else if (speed >= (1024 * 1024 * 1024) && speed < (1024 * 1024 * 1024 * 1024)) { str = df.format(speed / (1024 * 1024 * 1024.0)) + "TB/s"; }/* w w w.j a v a 2 s . c o m*/ return str; } }