Here you can find the source of getSpeedString(long castTime, long bytes)
public static String getSpeedString(long castTime, long bytes)
//package com.java2s; import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { private static final NumberFormat SIZE_FORMAT_M = new DecimalFormat("###.##M/s"); private static final NumberFormat SIZE_FORMAT_K = new DecimalFormat("####K/s"); public static String getSpeedString(long castTime, long bytes) { double castSecond = (double) castTime / (double) 1000; return parseSpeedString((long) ((double) bytes / castSecond) / 1024); }//w ww.j a v a 2 s .c om private static String parseSpeedString(long size) { if (size > 1024) { return SIZE_FORMAT_M.format(((float) size) / 1024); } return SIZE_FORMAT_K.format(size); } }