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 } }