I saw this beautiful script to add thousands separator to js numbers:
function thousandSeparator(n, sep) { var sRegExp = new RegExp(\'(-?[0-9]+)([0-9]{3
Try this one:
result = subject.replace(/([0-9]+?)([0-9]{3})(?=.*?\.|$)/mg, "$1,$2");
Test here