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