Java Currency Format formatCurrency(double amt)

Here you can find the source of formatCurrency(double amt)

Description

Will format the currency according to the current users locale.

License

Apache License

Parameter

Parameter Description
amt a parameter

Declaration

public static String formatCurrency(double amt) 

Method Source Code

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

import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    /**/*from  w  w  w .j  a  va 2  s.co  m*/
     * Will format the currency according to the current users locale.
     * 
     * @param amt
     * @return
     */
    public static String formatCurrency(double amt) {
        return formatCurrency(amt, 2);
    }

    public static String formatCurrency(double amt, int fractionDigits) {
        return getCurrencyFormat(fractionDigits).format(amt);
    }

    public static NumberFormat getCurrencyFormat() {
        return getCurrencyFormat(2);
    }

    public static NumberFormat getCurrencyFormat(int fractionDigits) {
        NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

        if (fractionDigits != 2) {
            nf.setMinimumFractionDigits(fractionDigits);
            nf.setMaximumFractionDigits(fractionDigits);
        }

        return nf;
    }
}

Related

  1. formatAsCurrency(Number value)
  2. formatCurrency(BigDecimal amount)
  3. formatCurrency(BigDecimal bd)
  4. formatCurrency(double amount)
  5. formatCurrency(double amount, int precision, Locale locale)
  6. formatCurrency(double num)
  7. formatCurrency(Double number)
  8. formatCurrency(Double value)
  9. formatCurrency(final Double currencyValue, final Locale locale, final boolean isGroup)