金额格式化方法集锦

在网上搜罗的金额格式化方法

方法一

    function toThousands(num) {
        var num = (num || 0).toString(), result = '';
        while (num.length > 3) {
            result = ',' + num.slice(-3) + result;
            num = num.slice(0, num.length - 3);
        }
        if (num) { result = num + result; }
        return result;
    }

 

posted @ 2017-01-09 16:20  知九  阅读(406)  评论(0)    收藏  举报