Java Utililty Methods Percentage Format

List of utility methods to do Percentage Format

Description

The list of methods to do Percentage Format are organized into topic(s).

Method

StringcalcPercent(double numerator, double denominator)
calc Percent
double fen = numerator / denominator;
DecimalFormat df = new DecimalFormat("##0.00%"); 
return df.format(fen);
StringformatAsPercent(double value, double maxValue, int fractionDigits)
format As Percent
return format(value * 100d / maxValue, fractionDigits, false) + "%";
StringformatDecimal(double percent)
Rounds the number to the 4 decimal points
NumberFormat formatter = new DecimalFormat("#0.0####");
return formatter.format(percent);
StringformatDoubleAsPercentString(Double d)
format Double As Percent String
if (d == null)
    return null;
return NumberFormat.getPercentInstance().format(d);
StringformatMicrosAsPercentage(long micros)
format Micros As Percentage
BigDecimal percentage = new BigDecimal(micros).divide(MICROS_DIVISOR, 6, BigDecimal.ROUND_HALF_UP);
return PERCENT_FORMAT.format(percentage);
StringformatPercent(double done, int digits)
Format a percentage for presentation to the user.
DecimalFormat percentFormat = new DecimalFormat("0.00%");
double scale = Math.pow(10.0, digits + 2);
double rounded = Math.floor(done * scale);
percentFormat.setDecimalSeparatorAlwaysShown(false);
percentFormat.setMinimumFractionDigits(digits);
percentFormat.setMaximumFractionDigits(digits);
return percentFormat.format(rounded / scale);
StringformatPercent(Double num1, Double num2)
format Percent
if (num1 == null || num2 == null || num2 == 0)
    return "";
String format = "0.00%";
if (num1.intValue() == num1.doubleValue() && num2.intValue() == num2.doubleValue()) {
    format = "0%";
return formatPercent(num1, num2, format);
StringformatPercent(double p_double, int p_decimals)
Formats a percent as a string in a standard way
NumberFormat format = NumberFormat.getPercentInstance();
format.setMinimumFractionDigits(p_decimals);
return format.format(p_double);
StringformatPercent(double percent)
Format a number as a percent in the current locale.
NumberFormat percentFormat = NumberFormat.getPercentInstance();
return percentFormat.format(percent);
StringformatPercent(double v)
format Percent
return formatPercent(new Double(v));