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;
    }

 

原文地址:https://www.cnblogs.com/yuanye007/p/5829889.html