Java BigDecimal Format format(BigDecimal num)

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

Description

format

License

LGPL

Declaration

public static String format(BigDecimal 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 {/* w w w . j  a  va2 s. co  m*/
            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(BigDecimal decimal)
  2. format(BigDecimal n, int prec)
  3. format(BigDecimal n, int prec)
  4. format(BigDecimal no, String formatter)
  5. format(BigDecimal num)
  6. format(BigDecimal num)
  7. format(BigDecimal number, String format)
  8. format(final BigDecimal bd)
  9. format(Object value, Integer precision)