Java Money Format format2Money(double value)

Here you can find the source of format2Money(double value)

Description

format Money

License

Open Source License

Declaration

public static String format2Money(double value) 

Method Source Code


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

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    /** EMPTY [String] */
    public static final String EMPTY = "";
    public static NumberFormat format = new DecimalFormat("0");
    public static NumberFormat format2 = new DecimalFormat("0.00");

    public static String format2Money(double value) {
        return format2.format(value);
    }/*  ww  w. ja v a 2 s  . c o m*/

    public static String format(Object object) {

        if (object instanceof Double) {
            return formatDouble((Double) object);
        } else {
            Double val = toDouble(object);

            if (val != null) {
                return formatDouble(val);
            }
        }

        return EMPTY;
    }

    public static String formatDouble(double value) {
        return format.format(value);
    }

    public static Double toDouble(Object value) {

        try {
            if (value == null || EMPTY.equals(value)) {
                return null;
            }
            return Double.valueOf(value.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}

Related

  1. beautifyMoney(long money)
  2. format(Object money)
  3. formatBookkeeperMoney(double cents, Locale locale)
  4. formatDoubleToMoneyString(double num)
  5. formatMoney(BigDecimal bd)
  6. formatMoney(BigDecimal money, Locale locale)