format Decimal Amount - Java java.text

Java examples for java.text:DecimalFormat

Description

format Decimal Amount

Demo Code


//package com.java2s;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {


    public static String formatDecimalAmount(double amount,
            String currencyCode, Character decimalSep,
            Character groupingSep, String currencySymbol,
            String formatPattern) {
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();

        if (null != currencySymbol) {
            dfs.setCurrencySymbol(currencySymbol);
        }//from   w  w w  .j  av a2  s.  c  o  m

        if (null != decimalSep) {
            dfs.setDecimalSeparator(decimalSep);
        }

        if (null != groupingSep) {
            dfs.setGroupingSeparator(groupingSep);
        }

        DecimalFormat decf = new DecimalFormat(formatPattern, dfs);

        return decf.format(amount);
    }
}

Related Tutorials