Java Currency Format formatCurrency(Number currencyValue)

Here you can find the source of formatCurrency(Number currencyValue)

Description

Method formatCurrency.

License

Open Source License

Parameter

Parameter Description
currencyValue a parameter

Return

String

Declaration

public static String formatCurrency(Number currencyValue) 

Method Source Code

//package com.java2s;

import java.text.NumberFormat;

public class Main {
    /**/*from   ww w  . java 2  s.co  m*/
     * Method formatCurrency. Return currency value as string.
     * 
     * @param currencyValue
     * @return String
     */
    public static String formatCurrency(Number currencyValue) {
        if (currencyValue == null)
            return "";

        if (currencyValue.doubleValue() == currencyValue.longValue())
            return "" + currencyValue.longValue();
        else {
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(2);
            nf.setMinimumFractionDigits(2);
            return nf.format(currencyValue);
        }
    }
}

Related

  1. formatCurrency(Double value)
  2. formatCurrency(final Double currencyValue, final Locale locale, final boolean isGroup)
  3. formatCurrency(Float amt)
  4. formatCurrency(Float f)
  5. formatCurrency(int amount)
  6. formatCurrency(Object value)
  7. formatCurrency(String currency)
  8. formatCurrencyWithCurrencyUnit(double amt, int fractionDigits)
  9. getCurrencyFormat()