js数字转换成财务金额

function dealNumberToMoney(money){
    var fmtAmt = "";
    if(money&&money!=null){
        money = money.replace(/,/g,"").replace(/,/g,"");
        if(money.indexOf(".")==-1){
            money = money + ".00";
        }
        
        var index = money.indexOf(".");
        var floatValue = money.substring(index+1);
        
        var count = 0;
        for(var i=(index);i>=0;i--){
            fmtAmt = money[i]+fmtAmt;
            if(count==3&&i!=0){
                fmtAmt = "," + fmtAmt;
                count = 0;
            }
            count++;
        }
    }
    
    fmtAmt += floatValue;
    
       return fmtAmt;
}

猜你喜欢

转载自www.cnblogs.com/jinzhiming/p/9810052.html