Here you can find the source of formatCurrencyWithCurrencyUnit(double amt, int fractionDigits)
public static String formatCurrencyWithCurrencyUnit(double amt, int fractionDigits)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; public class Main { public static String formatCurrencyWithCurrencyUnit(double amt, int fractionDigits) { NumberFormat nf = getCurrencyFormat(fractionDigits); String currAmt = nf.format(amt); String symbol = (nf instanceof DecimalFormat) ? ((DecimalFormat) nf).getDecimalFormatSymbols().getCurrencySymbol() : ""; if (symbol.length() == 1) { currAmt = currAmt + " " + nf.getCurrency(); }//from ww w . j a v a 2 s . c om return currAmt; } 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; } }