Java Percentage Format formatPercent(double p_double, int p_decimals)

Here you can find the source of formatPercent(double p_double, int p_decimals)

Description

Formats a percent as a string in a standard way

License

Open Source License

Parameter

Parameter Description
p_double The double to be interpreted as a percent
p_decimals The number of decimals to use

Return

The formatted string

Declaration

public static String formatPercent(double p_double, int p_decimals) 

Method Source Code

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

import java.text.NumberFormat;

public class Main {
    /**//from w  ww .  j a  v  a 2 s  . c  om
     * Formats a percent as a string in a standard way
     * @param p_double The double to be interpreted as a percent
     * @param p_decimals The number of decimals to use
     * @return The formatted string
     */
    public static String formatPercent(double p_double, int p_decimals) {
        NumberFormat format = NumberFormat.getPercentInstance();
        format.setMinimumFractionDigits(p_decimals);
        return format.format(p_double);
    }
}

Related

  1. formatDecimal(double percent)
  2. formatDoubleAsPercentString(Double d)
  3. formatMicrosAsPercentage(long micros)
  4. formatPercent(double done, int digits)
  5. formatPercent(Double num1, Double num2)
  6. formatPercent(double percent)
  7. formatPercent(double v)
  8. formatPercent(double v)
  9. formatPercent(final long value, final long total)