Java Utililty Methods Fraction Format

List of utility methods to do Fraction Format

Description

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

Method

StringformatNumber(Double number, String pattern)
format Number
DecimalFormat df = new DecimalFormat(pattern);
return df.format(number);
DoubleformatNumber(Double numberToFormat, int decimalPlacement)
format Number
if (decimalPlacement == 0) {
    return new Double(Math.round(numberToFormat.floatValue()));
NumberFormat numberFormat = NumberFormat.getInstance();
StringBuffer stringBuffer = new StringBuffer();
FieldPosition fieldPosition = new FieldPosition(0);
numberFormat.setGroupingUsed(false);
numberFormat.setMaximumFractionDigits(decimalPlacement);
...
StringformatNumber(double paramDouble, int paramInt)
format Number
return NumberFormat.getNumberInstance().format(round(paramDouble, paramInt));
StringformatNumber(double pValue)
format Number
java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(",##0.00");
java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
symbols.setGroupingSeparator(',');
symbols.setDecimalSeparator('.');
formatDecimal.setDecimalFormatSymbols(symbols);
return formatDecimal.format(pValue).toString();
StringformatNumber(double value)
Formats a specified numeric (int or real) value.
if (value >= 100) {
    return formatInt(value);
} else if (value >= 0.995) {
    return REAL_FORMAT_1.format(value);
} else if (value >= 0.0995) {
    return REAL_FORMAT_2.format(value);
} else if (value >= 0.00995) {
    return REAL_FORMAT_3.format(value);
...
StringformatNumber(double value, double epsilon)
Formats a number so that it presents a number of significant figures corresponding to a supplied small difference.
epsilon = Math.abs(epsilon);
double aval = Math.abs(value);
int nsf = Math.max(0, (int) Math.round(-Math.log10(epsilon / aval)));
if (aval >= 1e6 || aval <= 1e-4) {
    return formatNumber(value, "0.#E0", nsf);
} else if (epsilon >= 0.9) {
    return Long.toString((long) Math.round(value));
} else {
...
StringformatNumber(final double number)
format Number
return formatNumber(number, true);
StringformatNumber(Float d, int scalar)
format Number
float temp = d.floatValue();
return formatNumber(temp, scalar);
StringformatNumber(float num, String format)
format the number
DecimalFormat df = new DecimalFormat(format);
return df.format(num);
StringformatNumber(int fractionDigits, double value)
format Number
if (fractionDigits >= 0 && fractionDigits <= 10) {
    return nfs.get(fractionDigits).format(value);
throw new RuntimeException("Only supports fraction digits between 0 to 10");