Java Percentage Format formatPercent(double percent)

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

Description

Format a number as a percent in the current locale.

License

Apache License

Parameter

Parameter Description
percent as a decimal value where 1 is 100%

Return

A string representing the percentage in the current locale

Declaration

public static String formatPercent(double percent) 

Method Source Code

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

import java.text.NumberFormat;

public class Main {
    /**//from   w w  w .j a v a2 s.co  m
     * Format a number as a percent in the current locale.
     * The expected number is a decimal value where 1 = 100%, 0.5 = 50%, 1.5 = 150% etc...
     *
     * 
     * @param percent as a decimal value where 1 is 100%
     * @return A string representing the percentage in the current locale
     */
    public static String formatPercent(double percent) {
        NumberFormat percentFormat = NumberFormat.getPercentInstance();

        return percentFormat.format(percent);
    }

    public static String formatPercent(double percent, int maximumFractionDigits) {
        NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(maximumFractionDigits);
        return percentFormat.format(percent);
    }
}

Related

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