Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Comma Numbers

DZone's Guide to

Comma Numbers

·
Free Resource


function comma(number) { // oh dear god...
	str = new String(number);
	var val = new String();
	var num = str.length % 3;
	if (num == 0) { num = 3; }
	while (str.length > 0) {
		val += str.substring (0, num) + ",";
		str = str.substring (num);
		num = 3;
	}
	return val.substring (0, val.length - 1);
}
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}