Here you can find the source of formatAmtByComma(String amt, int len)
public static String formatAmtByComma(String amt, int len)
//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); } }