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

Stringformat(Double num)
format
java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
return df.format(num);
Stringformat(Double num)
format
String result = "";
try {
    result = new DecimalFormat(numericFormat).format(num);
} catch (Exception e) {
return result;
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 num, String pattern)
format
DecimalFormat doubleFormat = new DecimalFormat(pattern);
String resultStr = doubleFormat.format(num);
return resultStr;
Stringformat(double number)
format
DecimalFormat vf = new DecimalFormat("#00.#E0");
String str = vf.format(number);
str = str.replace("E0", " ");
str = str.replace("E3", "k");
str = str.replace("E6", "M");
str = str.replace("E9", "G");
str = str.replace("E12", "T");
str = str.replace("E-3", "m");
...
Stringformat(double number)
format
if (number == (int) number)
    return String.valueOf((int) number);
else
    return String.valueOf(number);
Stringformat(double number)
format
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(0);
format.setGroupingUsed(false);
return format.format(number);
doubleformat(double number, int digits)
Use this method like this:
String formatted = Util.format(1234.67789, 2);
formatted ==> "1234.68"
return format("" + number, digits);
Stringformat(double number, String fmt)
format
return new DecimalFormat(fmt).format(number);
Stringformat(double price)
format
DecimalFormat formatter = new DecimalFormat("###,###,##0.00");
return formatter.format(price);