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

StringpercentFormat(final double value)
percent Format
final NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMaximumFractionDigits(2);
return nf.format(value);
StringpercentFormat(float value)
percent Format
return PERCENT_FORMAT.format(value * 100.0f);
StringpercentFormat(Object object)
percent Format
if (object == null) {
    return "";
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMaximumFractionDigits(2);
return percent.format(object);
StringpercentTotal(double value, double total)
percent Total
if (total <= 0) {
    return "0%";
final DecimalFormat df = new DecimalFormat("#.00");
double result = (value * 100) / total;
if (result > 0.01) {
    return df.format(result);
return "0.00";
booleanroundedPercentageGreaterThan(double left, double right)
rounded Percentage Greater Than
return (left > right) && !formatPercentage(left).equals(formatPercentage(right));
StringtoPercent(Double doubleValue)
Format in percent value
DecimalFormat df = new DecimalFormat("###.##%");
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
String formatDouble = "";
if (doubleValue != null) {
    formatDouble = df.format(doubleValue);
return formatDouble;
...
StringtoPercent(double percent)
to Percent
return FORMAT_PERCENT.format(percent) + "%";
StringtoPercent(double value)
to Percent
return toPercent(value * 100.0, 100.0);
StringtoPercent(float f)
to Percent
if (Float.isNaN(f)) {
    return "0";
DecimalFormat df = new DecimalFormat("0.00");
return df.format(f);