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

intgetIntRoundPercent(double f)
get Int Round Percent
DecimalFormat df = new DecimalFormat("#####");
Double.parseDouble(df.format(f));
return Integer.parseInt(df.format(f));
StringgetOneDecimalPercentFromDouble(double inValue)
Return a percent value with 1 decimal value and the % at the end: 98.7% used everywhere for example to show quality and reference evaluation values in the table
String shortString = "";
if (!(new Double(inValue)).isNaN()) {
    double d = inValue * 100;
    DecimalFormat oneDec = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.US));
    shortString = (oneDec.format(d));
    shortString += "%";
} else
    shortString = "0.0%";
...
StringgetPercentage(double number)
get Percentage
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
return nf.format(number);
StringgetPercentage(double number, int fractionDigits)
get Percentage
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMaximumFractionDigits(fractionDigits);
nf.setMinimumFractionDigits(fractionDigits);
return nf.format(number);
StringgetPercentage(int numerator, int denominator)
get Percentage
return getPercentage(numerator * 1.00, denominator * 1.00);
StringgetPercentage(long duration, long lapso)
get Percentage
nf.setMaximumFractionDigits(1);
nf.setMinimumFractionDigits(1);
return nf.format((float) duration / (float) lapso * 100) + "%";
StringgetPercentage(long numerator, long denominator)
Find percentage of numerator of denominator
if (denominator == 0) {
    return "NaN";
double percentage = ((double) numerator / (double) denominator) * 100;
if ((long) (percentage) == 0) {
    return "0 %";
DecimalFormat df = new DecimalFormat("0.00");
...
StringgetPercentageString(double percent)
get Percentage String
return df.format(percent * 100f) + "%";
StringgetRoundPercent(double f)
get Round Percent
DecimalFormat df = new DecimalFormat("#####.00");
return df.format(f);
StringnumberToPercent2Scale(Double number)
formats the number {Category} NumberUtil {talendTypes} String {param} double(2.5) number: number to format {example} numberToPercent2Scale(0.12345) result: 12,34%
if (number != null) {
    return numberToString(roundScale2(number * 100d)) + "%";
} else {
    return "";