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

Stringpercent(double number)
percent
return new DecimalFormat("0.00%").format(number);
Stringpercent(double p1, double p2)
percent
String str;
if (p1 == 0.0) {
    return "0.00";
double p3 = p1 / p2;
DecimalFormat df1 = new DecimalFormat(".00");
if (p3 * 100 < 1) {
    df1 = new DecimalFormat("0.00");
...
Stringpercentage(Double v, String postfix)
percentage
return new DecimalFormat("0.00").format(100. * v) + postfix;
Stringpercentage(float f)
f should be in the range 0 - 1
if (f < 0f || f > 1f)
    throw new IllegalArgumentException();
return padToMinWidth(f * 100, 3) + "%";
StringpercentageAsString(double input)
Format the input percentage as a string (using the default locale).
return _format(input, NumberFormat.getPercentInstance());
StringpercentageFormat(BigDecimal value)
percentage Format
return new DecimalFormat(PERCENTAGE_FORMAT).format(value);
StringpercentDecimalFormat(final double no)
percent Decimal Format
final DecimalFormat PERCENT_DECIMAL_FORMAT = ((DecimalFormat) DecimalFormat.getNumberInstance());
PERCENT_DECIMAL_FORMAT.applyPattern("00.00");
return PERCENT_DECIMAL_FORMAT.format(no);
DecimalFormatpercentFormat()
percent Format
DecimalFormat format = decimalFormat();
format.setPositiveSuffix("%");
format.setNegativeSuffix("%");
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
format.setRoundingMode(RoundingMode.HALF_UP);
return format;
StringpercentFormat(BigDecimal interestRate)
percent Format
if (interestRate == null)
    return null;
return percentFormat.format(interestRate.doubleValue() * 100) + "%";
StringpercentFormat(final BigDecimal bd)
return a Number formatted or empty string if null.
return bd != null ? NUMBER_FORMAT.format(bd.movePointRight(2)) : "";