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

doubleformatDouble(double orig)
format Double
DecimalFormat df = new DecimalFormat("######0.000");
return Double.valueOf(df.format(orig)).doubleValue();
StringformatDouble(Double someDouble)
Formats a double as a string with a default number of significant digits depending on the argument's value.
return formatDouble(someDouble, false);
StringformatDouble(Double v)
format Double
try {
    DecimalFormat df = new DecimalFormat();
    df.setGroupingUsed(false);
    df.setMaximumFractionDigits(12);
    return df.format(v);
} catch (java.lang.IllegalArgumentException e) {
    return v.toString();
StringformatDouble(double value)
format Double
return formatter.format(value);
StringformatDouble(double value)
format Double
return Double.isNaN(value) ? "NaN" : _decimalFormat.format(value);
StringformatDouble(double value, int precision)
Returns a formatted Double value given a specific DecimalFormat
If more than 4 integer, then we display the value in scientific notation
String result;
if (((int) value) > 9999 || ((int) value) < -9999) {
    result = new DecimalFormat("0.######E0").format(value);
} else
    result = String.valueOf(roundDouble(value, precision));
return result == null ? "-" : result;
java.lang.StringFormatDouble(final double dblValue, final int iNumLeft, final int iNumRight, final double dblMultiplier)
Format the double input by multiplying, and then adding left and right adjustments
java.lang.String strFormat = "#";
for (int i = 0; i < iNumLeft; ++i)
    strFormat += "0";
if (0 != iNumRight) {
    strFormat += ".";
    for (int i = 0; i < iNumRight; ++i)
        strFormat += "0";
return new java.text.DecimalFormat(strFormat).format(dblMultiplier * dblValue);
StringformatDouble(Object obj)
format Double
DecimalFormat fmt = new DecimalFormat("#,##0.00");
String str = String.valueOf(obj);
if (obj instanceof Double) {
    return fmt.format(obj);
} else if (str.matches("^[-\\+]?\\d+(\\.\\d+)?$")) {
    return fmt.format(Double.valueOf(str));
} else {
    return toStringWithOutNull(str);
...
StringformatDouble(Object value)
format Double
NumberFormat doubleFormat = NumberFormat.getNumberInstance();
return doubleFormat.format(((Number) value).doubleValue());
StringformatDoubleAmount(double amount)
Formats the given double as a dollar amount, with negative amounts in parentheses.
NumberFormat formatter = new DecimalFormat("$#,###,##0.00;($#,###,##0.00)");
return formatter.format(amount);