Java Percentage Format formatPercent(double v)

Here you can find the source of formatPercent(double v)

Description

format Percent

License

Apache License

Declaration

public static String formatPercent(double v) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.NumberFormat;

public class Main {
    public static String formatPercent(double v) {
        return formatPercent(new Double(v));
    }/*from  w w  w  . j  a  va 2  s. co  m*/

    public static String formatPercent(Double v) {
        if (v == null) {
            return null;
        }
        return doubleFormat(v * 100) + "%";
    }

    /**
     * Formats a double to two decimal places
     *
     * @param d Double to format
     * @return Formatted double
     */
    public static String doubleFormat(Double d) {
        return doubleFormat(d, 0);
    }

    public static String doubleFormat(double d) {
        return doubleFormat(new Double(d));
    }

    public static String doubleFormat(Double d, int minFraction) {
        if (d == null) {
            return null;
        }
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        if (minFraction > 0) {
            nf.setMinimumFractionDigits(minFraction);
        }
        return nf.format(d);
    }

    public static String doubleFormat(double d, int minFraction) {
        return doubleFormat(new Double(d), minFraction);
    }
}

Related

  1. formatMicrosAsPercentage(long micros)
  2. formatPercent(double done, int digits)
  3. formatPercent(Double num1, Double num2)
  4. formatPercent(double p_double, int p_decimals)
  5. formatPercent(double percent)
  6. formatPercent(double v)
  7. formatPercent(final long value, final long total)
  8. formatPercent(float p_num)
  9. formatPercent1dp(double frac)