Android Float Format formatSpeedWithUnit(float speed)

Here you can find the source of formatSpeedWithUnit(float speed)

Description

format Speed With Unit

Declaration


public static Map<String, String> formatSpeedWithUnit(float speed) 

Method Source Code

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

Related

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