Java Fraction Format format(Double num)

Here you can find the source of format(Double num)

Description

format

License

LGPL

Declaration

public static String format(Double num) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Main {
    static String numericFormat = "#,##0.00";

    public static String format(Double num) {
        String result = "";
        try {/*from   w w  w  .ja  v a  2s .  c om*/
            result = new DecimalFormat(numericFormat).format(num);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    public static String format(Integer num) {
        String result = "";
        try {
            result = format((double) num);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    public static String format(String num) {
        String result = "";
        try {
            result = format(Double.parseDouble(num));
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    public static String format(BigDecimal num) {
        String result = "";
        try {
            result = format(num.doubleValue());
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }
}

Related

  1. format(double input, String format)
  2. format(double n)
  3. format(double no, String formatter)
  4. format(double num)
  5. format(Double num)
  6. format(double num, int n)
  7. format(double num, String pattern)
  8. format(double number)
  9. format(double number)