//format number for all controls html of the same class or id $(function(){ arr = $('.col_3.number'); //class or id name all controls to need format arrNumber = new Array(); for(var i = 0; i< arr.length;i++){ arrNumber[i] = formatMoney($(arr[i]).text()); $(arr[i]).text(arrNumber[i]); } }) function formatMoney(money) { decPlaces = 0; thouSeparator = ','; decSeparator = '.'; var n = money, decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces, decSeparator = decSeparator == undefined ? "." : decSeparator, thouSeparator = thouSeparator == undefined ? "," : thouSeparator, sign = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : ""); };