Android Int Format formatSpeed(int speed, String format)

Here you can find the source of formatSpeed(int speed, String format)

Description

format Speed

Declaration

public static String formatSpeed(int speed, String format) 

Method Source Code

//package com.java2s;

public class Main {

    public static String formatSpeed(float data) {

        return formatSpeed(data, "#0.00");

    }/*  ww w  .j a  va 2  s .c  om*/

    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. addCommas(int value)
  2. formatSpeed(int value)
  3. getDecimalFormat(int i, String numStr)
  4. formatGameSize(int size)
  5. formatSpeed(int value)
  6. formatId(String id)