I found some code on this site and tweaked it a bit so add commas to numbers that I pass to the function. Can anyone tell me why this doesn’t work? I know the function is receiving numbers because I had built in an alert to be sure.
Chart.prototype.getComma = function(r) {
var w = r.split(“”).reverse().join(“”);
var q = “”;
for (var i=0; i<w.length; i++) {
q += w.charAt(i);
if ((i + 1) % 3 == 0 && i+1 != w.length) {
q += “,”;
}
}
q = q.split(“”).reverse().join(“”);
return q
}
This does work when I change the r.split(“”).reverse().join(“”); to “123456789”.split(“”).reverse().join(“”); but it returns the #’s 1-9 as I have them hard-coded in. Why won’t the variable approach work here?
Thanks in advance.
Tom