Java Fraction Format formatDouble(Object obj)

Here you can find the source of formatDouble(Object obj)

Description

format Double

License

Open Source License

Declaration

public final static String formatDouble(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {

    public final static String formatDouble(Object obj) {
        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 {/*from   w w  w .  java  2s. c om*/
            return toStringWithOutNull(str);
        }
    }

    public final static String toStringWithOutNull(Object obj) {
        return obj == null ? "" : String.valueOf(obj);
    }
}

Related

  1. formatDouble(Double v)
  2. formatDouble(double value)
  3. formatDouble(double value)
  4. formatDouble(double value, int precision)
  5. FormatDouble(final double dblValue, final int iNumLeft, final int iNumRight, final double dblMultiplier)
  6. formatDouble(Object value)
  7. formatDoubleAmount(double amount)
  8. formatDoubleArray(double[] arr, String format)
  9. formatDoubleAsPointsString(Double d)