金钱数字千分符

function initNumber(number) {
            number= (typeof number=='number') ? number.toString() : number;
        var len = number.length;
        var newnumber = "";
        for (var i = 0; i < len; i++) {
            if ((i + 1) % 3 == 0) {
                newnumber += number.substr(0, 3) + ",";
                number = number.substr(3);
                if (number.length < 3) {
                    newnumber += number;
                }
            }
        }
        if (len > 3) {
            return newnumber
        } else {
            return number
        }
    }

 

posted @ 2018-08-27 15:30  秋月渔舟  阅读(310)  评论(0编辑  收藏  举报