用js实现千位分隔符

function mm(num) {
    return num && num
        .toString()
        .replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
            return $1 + ",";
        });
}
console.log(mm(4152465465456.454)); //4,152,465,465,456.454

 

posted @ 2018-12-24 10:41  疾风_剑豪  阅读(203)  评论(0编辑  收藏  举报