JavaScript 多位数字每隔三位加一个逗号

//每隔三位小数加逗号
function add_comma_toThousands(num) {
    var num = (num || 0).toString();
    var result = '';
    while (num.length > 3) {
        result = ',' + num.slice(-3) + result;
        num = num.slice(0, num.length - 3);
    }
    if (num) { result = num + result; }
    return result;
}

 

你可能感兴趣的:(javascript)