0); var tot_pop = 0; for(var i=0; i < num_rows; i++){ tot_pop = tot_pop+data[i]; }; tot_pop=Math.round(tot_pop/1000.0); tot_pop=tot_pop*1000; function addSeparatorsNF(nStr, inD, outD, sep) { nStr += ''; var dpos = nStr.indexOf(inD); var nStrEnd = ''; if (dpos != -1) { nStrEnd = outD + nStr.substring(dpos + 1, nStr.length); nStr = nStr.substring(0, dpos); } var rgx = /(\d+)(\d{3})/; while (rgx.test(nStr)) { nStr = nStr.replace(rgx, '$1' + sep + '$2'); } return nStr + nStrEnd; } document.getElementById('result').innerHTML=addSeparatorsNF(tot_pop, '.', '.', ',');