首页 > 其他 > 详细

DecimalFormat 格式化金额

时间:2016-09-01 15:56:55      阅读:222      评论:0      收藏:0      [点我收藏+]

 

DecimalFormat 格式化金额,是使用现有API还是自己写util方法?
public static void main(String[] args) throws Exception {
        DecimalFormat df = new DecimalFormat("#.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;
    }

 

DecimalFormat 格式化金额

原文:http://www.cnblogs.com/yuanye007/p/5829889.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!