DecimalFormat 格式化金额

 

DecimalFormat 格式化金额,是使用现有API还是自己写util方法?
public static void main(String[] args) throws Exception {
        DecimalFormat df = new DecimalFormat("###,###,###,###,##0.00");
        String re=df.format(23.8);
        System.out.println(re);
        
        String ss="23";
        System.out.println(ensureDecimalPlaceOfMoney(ss));
    }
    public static String ensureDecimalPlaceOfMoney(String money){
        if(money==null)
            return null;
        if(money.indexOf(".")!=-1){
            String decimalPlace=money.substring(money.indexOf(".")+1, money.length());
            if(decimalPlace.length()==1){
                money+="0";
            }
        }else{
            money+=".00";
        }
        return money;
    }

 

posted @ 2016-09-01 14:56  元页  阅读(755)  评论(0编辑  收藏  举报