davesmiths
6/16/2014 - 4:20 PM

Put commas into a number (js)

Put commas into a number (js)

// Quick a dirty

var start = 0;

do {
	start = start + 3;
	output = mynum.substr(-start, 3) + (output === '' ? '' : ',') + output;
}
while (mynum.length - start > 3);
if (mynum.length > start) {
	output = mynum.substr(0, mynum.length - start) + ',' + output;
}