Android Float Format formatSpeed(float bytesPerSecond)

Here you can find the source of formatSpeed(float bytesPerSecond)

Description

format Speed

Declaration

public static String formatSpeed(float bytesPerSecond) 

Method Source Code

//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
}

Related

  1. formatAmount(float f)
  2. formatSpeed(float data)
  3. formatSpeed(float data, String format)
  4. formatSpeedValue(float speed)
  5. formatSpeedWithUnit(float speed)
  6. priceFormat(float price, String pattern)