Java Utililty Methods Double Number Format

List of utility methods to do Double Number Format

Description

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

Method

StringconvertDouble(double damage)
Convert endless decimal health to a 2 lengthed one.
NumberFormat nf = new DecimalFormat("##.##");
return nf.format(damage);
StringdoubleFormat(Double d)
Formats a double to two decimal places
return doubleFormat(d, 0);
StringdoubleFormat(double d)
double Format
DecimalFormat df = new DecimalFormat("#########.###");
return df.format(d);
StringdoubleFormat(double number)
A number formatted in a String
NumberFormat nf_out = NumberFormat.getNumberInstance(Locale.UK);
nf_out.setMaximumFractionDigits(2);
return nf_out.format(number);
StringdoubleFormat(double val, boolean hiRes)
Format a double
if (Double.isNaN(val)) {
    return ("NaN");
double abs = Math.abs(val);
if (abs == 0.0) {
    return ("0.0");
} else if (abs < (hiRes ? 1.0E-2 : 1.0E-1)) {
    return (tinyNums_.format(val));
...
doubleformat(double b)
format
return Math.round(b * 100) / 100.0;
Stringformat(double d, int decimals)
Returns d as a string truncated to the specified number of decimal places
double factor = Math.pow(10, decimals);
double digits = Math.round(factor * d);
return ((int) Math.floor(digits / factor)) + "." + ((int) (digits % factor));
Stringformat(Double decimal)
Attempts to format a Double to a String to the #DEFAULT_PRECISION .
return format(decimal, DEFAULT_PRECISION);
doubleformat(double num, int n)
Formats a double with an specified number of decimals.
long m = (long) Math.pow(10, n);
num *= m;
long aux = ((long) num);
num = (double) ((double) aux / (double) m);
return num;
Stringformat(double number)
format
if (number == (int) number)
    return String.valueOf((int) number);
else
    return String.valueOf(number);