<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Formatting Numbers With Commas in AS3</title>
	<atom:link href="http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/</link>
	<description>A blog about interactive communications for marketers, designers and developers</description>
	<lastBuildDate>Thu, 24 Jun 2010 23:47:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andrew</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-44</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Thu, 24 Jun 2010 23:47:22 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-44</guid>
		<description>As with jack - this came in very handy and works as expected; thanks for sharing it.</description>
		<content:encoded><![CDATA[<p>As with jack &#8211; this came in very handy and works as expected; thanks for sharing it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nixon</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-17</link>
		<dc:creator>nixon</dc:creator>
		<pubDate>Tue, 30 Mar 2010 20:10:08 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-17</guid>
		<description>While your solution will work for any sized positive number it won&#039;t handle numbers with a decimal point.  

For example 5.25 would be formatted 5,.25

Our two functions aren&#039;t behaving that much differently, personally, I find the flexibility to work with negative numbers and decimal points is worth the extra few lines of code because I can reuse the same function anytime I need formatted numbers and don&#039;t have to revisit it when a special case comes along.</description>
		<content:encoded><![CDATA[<p>While your solution will work for any sized positive number it won&#8217;t handle numbers with a decimal point.  </p>
<p>For example 5.25 would be formatted 5,.25</p>
<p>Our two functions aren&#8217;t behaving that much differently, personally, I find the flexibility to work with negative numbers and decimal points is worth the extra few lines of code because I can reuse the same function anytime I need formatted numbers and don&#8217;t have to revisit it when a special case comes along.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-16</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Mon, 29 Mar 2010 17:28:53 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-16</guid>
		<description>I took a different approach -- should work for any sized number. I didn&#039;t need the negative detection, you should be able to add that to this easily if you need it. 

		public function addCommas(number:Number):String 
		{
			var numberString:String = String(number);
			var newString:String = &quot;&quot;;
			var col:int = 0;
			for (var index:int = numberString.length-1; index &gt;= 0; index--)
			{
				col++;
				newString = numberString.substr(index, 1) + newString;
				if (col == 3 &amp;&amp; index != 0)
				{
					newString = &quot;,&quot; + newString;
					col = 0;
				}
				
			}
			return newString;
		}</description>
		<content:encoded><![CDATA[<p>I took a different approach &#8212; should work for any sized number. I didn&#8217;t need the negative detection, you should be able to add that to this easily if you need it. </p>
<p>		public function addCommas(number:Number):String<br />
		{<br />
			var numberString:String = String(number);<br />
			var newString:String = &#8220;&#8221;;<br />
			var col:int = 0;<br />
			for (var index:int = numberString.length-1; index &gt;= 0; index&#8211;)<br />
			{<br />
				col++;<br />
				newString = numberString.substr(index, 1) + newString;<br />
				if (col == 3 &amp;&amp; index != 0)<br />
				{<br />
					newString = &#8220;,&#8221; + newString;<br />
					col = 0;<br />
				}</p>
<p>			}<br />
			return newString;<br />
		}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-12</link>
		<dc:creator>Jack</dc:creator>
		<pubDate>Wed, 27 Jan 2010 01:39:13 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-12</guid>
		<description>Thanks for posting the code. Works great and saved me a ton of time. 

-Jack</description>
		<content:encoded><![CDATA[<p>Thanks for posting the code. Works great and saved me a ton of time. </p>
<p>-Jack</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nixon</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-10</link>
		<dc:creator>Nixon</dc:creator>
		<pubDate>Wed, 18 Nov 2009 14:42:42 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-10</guid>
		<description>hey there Wyeth, 
I&#039;ve cranked some pretty big numbers through the function without a problem... 

I think the issue is that line you break out: 
var mod:Number = num.length/3;

In actuality should read:
var mod:Number = num.length%3;

The percent sign being the modulus math operation.  The modulus operator is doing the same thing as your switch statement in that, 4%3 = 1, 5%3=2 etc etc.  Unfortunately the switch statement you&#039;ve outlined won&#039;t work on numbers with more than 9 digits.

I would replace the switch with this:
var mod:Number = num.length%3;

I think the problem is from wordpress really butchering the code format... maybe I can attach a file for download...</description>
		<content:encoded><![CDATA[<p>hey there Wyeth,<br />
I&#8217;ve cranked some pretty big numbers through the function without a problem&#8230; </p>
<p>I think the issue is that line you break out:<br />
var mod:Number = num.length/3;</p>
<p>In actuality should read:<br />
var mod:Number = num.length%3;</p>
<p>The percent sign being the modulus math operation.  The modulus operator is doing the same thing as your switch statement in that, 4%3 = 1, 5%3=2 etc etc.  Unfortunately the switch statement you&#8217;ve outlined won&#8217;t work on numbers with more than 9 digits.</p>
<p>I would replace the switch with this:<br />
var mod:Number = num.length%3;</p>
<p>I think the problem is from wordpress really butchering the code format&#8230; maybe I can attach a file for download&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wyeth</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-9</link>
		<dc:creator>Wyeth</dc:creator>
		<pubDate>Tue, 17 Nov 2009 23:53:23 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-9</guid>
		<description>Hi there,
   Thanks for your script. It helped me. I had a problem though. When the number got up into higher digits, the commas were being placed in the wrong places. I tried a few things and then ended up replacing

var mod:Number = num.length/3;

with a switch statement:

switch(num.length){
		case 4:
		mod = 1;
		break;
		
		case 5:
		mod = 2;
		break;
		
		case 6:
		mod = 3;
		break;
		
		case 7:
		mod = 1;
		break;
		
		case 8:
		mod = 2;
		break;
		
		case 9:
		mod = 3;
		break;
		}

It worked perfectly after that.

Thanks again,

Best,

-w</description>
		<content:encoded><![CDATA[<p>Hi there,<br />
   Thanks for your script. It helped me. I had a problem though. When the number got up into higher digits, the commas were being placed in the wrong places. I tried a few things and then ended up replacing</p>
<p>var mod:Number = num.length/3;</p>
<p>with a switch statement:</p>
<p>switch(num.length){<br />
		case 4:<br />
		mod = 1;<br />
		break;</p>
<p>		case 5:<br />
		mod = 2;<br />
		break;</p>
<p>		case 6:<br />
		mod = 3;<br />
		break;</p>
<p>		case 7:<br />
		mod = 1;<br />
		break;</p>
<p>		case 8:<br />
		mod = 2;<br />
		break;</p>
<p>		case 9:<br />
		mod = 3;<br />
		break;<br />
		}</p>
<p>It worked perfectly after that.</p>
<p>Thanks again,</p>
<p>Best,</p>
<p>-w</p>
]]></content:encoded>
	</item>
</channel>
</rss>
