将double形式的钱格式化为money的形式

类别:Java 点击:0 评论:0 推荐:

import java.text.*;
public class UT {
    private final static DecimalFormat nf = new DecimalFormat("###,##0.00");
    public static String formatToMoney(String s) {
        if (s == null || s.equals("")) {
            return "0.00";
        }
        try {
            return formatToMoney(Double.parseDouble(s));
        } catch (Exception e) {
            return s;
        }
    }

    public static String formatToMoney(double d) {
        try {
            return nf.format(d);
        } catch (Exception e) {
            return String.valueOf(d);
        }
    }
    public static void main(String[] args){
        String dd=Client.formatToMoney("12345678990.78987");
        System.out.println(dd);

   }
}

本文地址:http://com.8s8s.com/it/it17672.htm