DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

FormatNumberWidthCommas

05.04.2008
| 180 views |
  • submit to reddit
        // description of your code here

function formatNumberWithCommas( num )
{
	var strNum:String = num + "";
	
	if ( strNum.length < 4 )
	{
		return strNum;
	}
	return formatNumberWithCommas( strNum.slice( 0, -3 ) ) + "," + strNum.slice( -3 );
}

trace( this.formatNumberWithCommas( 209 ) );