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

StringformatDoubleArray(double[] arr, String format)
format Double Array
DecimalFormat fmt = new DecimalFormat(format);
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < arr.length; i++) {
    if (i > 0) {
        sb.append(", ");
    sb.append(fmt.format(arr[i]));
...
StringformatDoubleAsPointsString(Double d)
format Double As Points String
if (d == null)
    return "";
return NumberFormat.getInstance().format(d);
StringformatDoubleAsString(Double val)
format Double As String
return formatDoubleAsString(val, 2);
StringformatDoubleDecimal(float in)
format Double Decimal
DecimalFormat df = new DecimalFormat();
df.applyPattern("0.00");
return df.format(in);
doubleformatDoubleDecPoint2(Double value)
format Double Dec Point
try {
    java.text.DecimalFormat form = new java.text.DecimalFormat("##.00");
    String s = form.format(value);
    return Double.valueOf(s);
} catch (Exception e) {
    return 0.0;
StringformatDoubleList(List list)
format Double List
return formatDoubleList(list, decimalFormat);
StringformatDoubleString(double data, String pattern)
format Double String
DecimalFormat format = new DecimalFormat(pattern);
if (data < 0) {
    return "0";
if ((int) (data * 10) == (int) (data) * 10) {
    return (int) data + "";
} else {
    return format.format(data);
...
DoubleformatDoubleValue(String originalVal, Double valToProcess)
Converts a double value to contain decimal places in the frequency the original value was recorded.
StringBuffer format = new StringBuffer("#");
int numDecimals;
int numKeyVals = originalVal.length();
if (originalVal.contains(".")) {
    format.append(".");
    numDecimals = originalVal.substring(originalVal.lastIndexOf(".") + 1).trim().length();
    for (int i = 0; i < numDecimals; i++) {
        format.append("#");
...
StringformateNum(double num)
formate Num
NumberFormat f = NumberFormat.getInstance();
f.setMaximumFractionDigits(4);
return f.format(num);
floatformatFloat(double val1, double val2)
format Float
return val2 == 0 ? 0 : Float.parseFloat(floatFormatter.format(val1 / val2));