Android Float Format formatSpeed(float data, String format)

Here you can find the source of formatSpeed(float data, String format)

Description

format Speed

Declaration

public static String formatSpeed(float data, String format) 

Method Source Code

//package com.java2s;

public class Main {

    public static String formatSpeed(float data) {

        return formatSpeed(data, "#0.00");

    }/*from   www  .j  a  v  a  2s . c o  m*/

    public static String formatSpeed(float data, String format) {
        java.text.DecimalFormat df = new java.text.DecimalFormat(format);

        if (data < 0)
            return "0B/s";

        if (data < 1000.0) {
            if (data == (int) data) {
                df = new java.text.DecimalFormat("#0");
            }
            return df.format(data) + "KB/s";
        }

        if (data < (1000f * 1024.0))
            return df.format(data / 1024) + "MB/s";

        if (data < (1000 * 1024 * 1024.0))
            return df.format(data / (1024 * 1024.0)) + "GB/s";

        return df.format(data / (1024 * 1024 * 1024.0)) + "GB/s";
    }

    public static String formatSpeed(int speed, String format) {
        java.text.DecimalFormat df = new java.text.DecimalFormat(format);
        if (speed < 0)
            return "0B/s";

        if (speed < 1000) {
            return speed + "B/s";
        }

        if (speed < 1000f * 1024.0)
            return df.format(speed / 1024) + "KB/s";

        return df.format(speed / (1024 * 1024.0)) + "MB/s";
    }
}

Related

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