Here you can find the source of formatSpeedWithUnit(float speed)
public static Map<String, String> formatSpeedWithUnit(float speed)
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { public static Map<String, String> formatSpeedWithUnit(float speed) { java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00"); Map<String, String> map = new HashMap<String, String>(); if (speed < 0) { map.put("speed", "0"); map.put("unit", "KB/s"); return map; }/*from ww w . j a v a 2s. c om*/ if (speed < 1000.0) { if (speed == (int) speed) { df = new java.text.DecimalFormat("#0"); } map.put("speed", df.format(speed)); map.put("unit", "KB/s"); return map; } if (speed < (1024 * 1000.0)) { map.put("speed", df.format(speed / 1024)); map.put("unit", "MB/s"); return map; } if (speed < (1024 * 1024 * 1000.0)) { map.put("speed", df.format(speed / (1024 * 1024.0))); map.put("unit", "GB/s"); return map; } map.put("speed", "0"); map.put("unit", "KB/s"); return map; } }