Java Currency Format formatAsCurrency(Number amount)

Here you can find the source of formatAsCurrency(Number amount)

Description

Convenience method for converting Number to currency string representation with minimal overhead.

License

Open Source License

Parameter

Parameter Description
amount Currency amount

Return

formatted currency string

Declaration

public static String formatAsCurrency(Number amount) 

Method Source Code

//package com.java2s;

import java.text.Format;
import java.text.NumberFormat;

public class Main {
    private static ThreadLocal<Format> CURRENCY_FORMAT = new ThreadLocal<Format>() {
        @Override/*from ww w.j  a  va  2 s . c o  m*/
        protected Format initialValue() {
            return NumberFormat.getCurrencyInstance();
        }
    };

    /**
     * Convenience method for converting {@link Number} to currency string
     * representation with minimal overhead.
     * 
     * <p>
     * Intended for use in KRAD SpEL expressions, for example:
     * </p>
     * 
     * <pre>
     * @{T(org.kuali.ole.krad.OleComponentUtils).formatAsCurrency(anAmount)}
     * </pre>
     * 
     * @param amount
     *            Currency amount
     * @return formatted currency string
     */
    public static String formatAsCurrency(Number amount) {
        return amount == null ? "" : CURRENCY_FORMAT.get().format(amount);
    }
}

Related

  1. currency(double value, NumberFormat nformat)
  2. currencyFormat()
  3. format2CurrencyWithComma(double amt)
  4. formatAsCurrency(BigDecimal nAmount)
  5. formatAsCurrency(final double value)
  6. formatAsCurrency(Number value)
  7. formatCurrency(BigDecimal amount)
  8. formatCurrency(BigDecimal bd)
  9. formatCurrency(double amount)