Java Number Format Pattern formatAmtByComma(String amt, int len)

Here you can find the source of formatAmtByComma(String amt, int len)

Description

format Amt By Comma

License

Open Source License

Declaration

public static String formatAmtByComma(String amt, int len) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {

    public static String formatAmtByComma(String amt, int len) {
        if (null == amt || amt.length() < 1) {
            return "0";
        }/*from w w  w .jav  a  2s . c om*/
        NumberFormat formater = null;
        BigDecimal num = new BigDecimal(amt);
        if (len == 0) {
            formater = new DecimalFormat("###,###");
        } else {
            StringBuffer buff = new StringBuffer();
            buff.append("###,###.");
            for (int i = 0; i < len; i++) {
                buff.append("#");
            }
            formater = new DecimalFormat(buff.toString());
        }
        return formater.format(num);
    }
}

Related

  1. format(Number value)
  2. format(Object num, int dev, String valueIfZero)
  3. format(Object price)
  4. format(String str_number, int digits)
  5. format(String value)
  6. formatBigNumber(long value)
  7. formatBitRate(long bytes)
  8. formatBytes(long bytes)
  9. formatBytes(long bytes)