Java Fraction Format formatPair(double in, double out)

Here you can find the source of formatPair(double in, double out)

Description

format Pair

License

Open Source License

Return

"x.xx / y.yy {K|M}"

Declaration

private static String formatPair(double in, double out) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    static final String THINSP = " / ";

    /**/*from w w w . j  a  va2s .  c  om*/
     *    @return "x.xx / y.yy {K|M}"
     */
    private static String formatPair(double in, double out) {
        boolean mega = in >= 1024 * 1024 || out >= 1024 * 1024;
        // scale both the same
        if (mega) {
            in /= 1024 * 1024;
            out /= 1024 * 1024;
        } else {
            in /= 1024;
            out /= 1024;
        }
        // control total width
        DecimalFormat fmt;
        if (in >= 1000 || out >= 1000)
            fmt = new DecimalFormat("#0");
        else if (in >= 100 || out >= 100)
            fmt = new DecimalFormat("#0.0");
        else
            fmt = new DecimalFormat("#0.00");
        return fmt.format(in) + THINSP + fmt.format(out) + " " + (mega ? 'M' : 'K');
    }
}

Related

  1. formatNumValueWithComma(double val)
  2. formatoDecimal(String tipo, double valor)
  3. formatOLETime(double oleTime)
  4. formatOneDecimal(double dNumber)
  5. formatOneDp(double inNumber)
  6. formatPotencia(float potencia)
  7. formatPowerFloat(float averageRfTickSent)
  8. formatPrice(Double price)
  9. formatQuantity(Double quantity)