I have a quirky problem formatting a number in JavaScript. I've borrowed a couple of functions from various sources on the web. Each works well except in one instance. Here is the executing code at the time of the error:
lth=appl.length+3;
var table = $("#unitsCompleted")[0];
var sum=0;
for(i=0; i<temp.length; i++){
sum += Number(table.rows[lth].cells[i+1].innerHTML);
}
var t=formatNumber(sum);
$("#mtf_retail").html("$ "+t);
The identical code is used in a couple other places. In fact was simply copied. Below is the formatting function:
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
It works fine except on the total 1787.78. In the image you can see that it perfectly formatted the total 1,249.69
num.toString(), trynum.toFixed(2)1:3means "line 1, column 3", aka "3rd character on first line"\of\d, which would hint that FF does not know\d. I can, however, hardly imagine that. SO it's more likely that it is the,in$1,, and FF is parsing1,as the name of the capture group, which is indeed invalid.