<?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>Fri, 16 Dec 2011 15:44:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: nixon</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-128</link>
		<dc:creator>nixon</dc:creator>
		<pubDate>Mon, 22 Nov 2010 19:17:10 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-128</guid>
		<description>That line could be causing problems if this function is converted to run with string variables.  But as I mentioned previously the main problem for @comment7 was the limit in AS3 to handle large numbers without some kind of additional framework.  Even trying to set a variable to one of those values and tracing it back gives the same results.

Anywho, the line you&#039;re referring to in your post:
 return negNum+output+”.”+results[1]+”0″; 

Is used to provide consistent formatting of numbers like 1.5  this line ensures that 1.50 is output instead.  Often times this code is used for calculators and most sales/marketing people like to see numbers as they would appear on a cash register or receipt.  Hence the additional 0.</description>
		<content:encoded><![CDATA[<p>That line could be causing problems if this function is converted to run with string variables.  But as I mentioned previously the main problem for @comment7 was the limit in AS3 to handle large numbers without some kind of additional framework.  Even trying to set a variable to one of those values and tracing it back gives the same results.</p>
<p>Anywho, the line you&#8217;re referring to in your post:<br />
 return negNum+output+”.”+results[1]+”0″; </p>
<p>Is used to provide consistent formatting of numbers like 1.5  this line ensures that 1.50 is output instead.  Often times this code is used for calculators and most sales/marketing people like to see numbers as they would appear on a cash register or receipt.  Hence the additional 0.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FlashMan</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-118</link>
		<dc:creator>FlashMan</dc:creator>
		<pubDate>Fri, 19 Nov 2010 04:05:15 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-118</guid>
		<description>@comment7:

I think the reason why &quot;0&quot; is added is because of this line:

return negNum+output+”.”+results[1]+”0″;

Why is the + &quot;0&quot; needed?

I removed it and now it works great, thank you!</description>
		<content:encoded><![CDATA[<p>@comment7:</p>
<p>I think the reason why &#8220;0&#8243; is added is because of this line:</p>
<p>return negNum+output+”.”+results[1]+”0″;</p>
<p>Why is the + &#8220;0&#8243; needed?</p>
<p>I removed it and now it works great, thank you!</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-66</link>
		<dc:creator>nixon</dc:creator>
		<pubDate>Tue, 12 Oct 2010 13:47:05 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-66</guid>
		<description>In general I stay away from formatting an input box.  I think it is a bit jarring for a user to be typing and having things autoformat without their consent.  I know plenty of people that can&#039;t even handle t9 on their cell phones.  Though, if you&#039;re looking to do it you just need to add a key_up event listener onto the input box.  better yet have the event listener on the next input box so that the number is only formatted once the user is no longer actively typing in the same box.  Know what I mean?</description>
		<content:encoded><![CDATA[<p>In general I stay away from formatting an input box.  I think it is a bit jarring for a user to be typing and having things autoformat without their consent.  I know plenty of people that can&#8217;t even handle t9 on their cell phones.  Though, if you&#8217;re looking to do it you just need to add a key_up event listener onto the input box.  better yet have the event listener on the next input box so that the number is only formatted once the user is no longer actively typing in the same box.  Know what I mean?</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-65</link>
		<dc:creator>nixon</dc:creator>
		<pubDate>Tue, 12 Oct 2010 13:43:38 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-65</guid>
		<description>Hey there,
Looking into this I see it&#039;s not so much the function having a problem, but it&#039;s a limit of AS3 to deal with large values like this.  AS3 doesn&#039;t really have the capacity to use those values as a number data type.  As you mentioned, changing this to a string will allow AS3 to properly format the number.  I can&#039;t even assign such values to a number variable and have it stored correctly, let alone run it through a function.  I wasn&#039;t aware of AS3&#039;s limitation on large numbers prior to this, so thanks for bringing it to my attention.  Supposedly there are classes in third party libraries like &quot;BigInteger&quot; to help facilitate some of this.</description>
		<content:encoded><![CDATA[<p>Hey there,<br />
Looking into this I see it&#8217;s not so much the function having a problem, but it&#8217;s a limit of AS3 to deal with large values like this.  AS3 doesn&#8217;t really have the capacity to use those values as a number data type.  As you mentioned, changing this to a string will allow AS3 to properly format the number.  I can&#8217;t even assign such values to a number variable and have it stored correctly, let alone run it through a function.  I wasn&#8217;t aware of AS3&#8242;s limitation on large numbers prior to this, so thanks for bringing it to my attention.  Supposedly there are classes in third party libraries like &#8220;BigInteger&#8221; to help facilitate some of this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: j_noob</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-63</link>
		<dc:creator>j_noob</dc:creator>
		<pubDate>Tue, 05 Oct 2010 01:00:49 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-63</guid>
		<description>i just want to ask how can I call the function in an input box?sorry just a jscript newbie..you&#039;re answers would be a great of help</description>
		<content:encoded><![CDATA[<p>i just want to ask how can I call the function in an input box?sorry just a jscript newbie..you&#8217;re answers would be a great of help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edenshaw</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-54</link>
		<dc:creator>Edenshaw</dc:creator>
		<pubDate>Mon, 13 Sep 2010 16:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-54</guid>
		<description>I change the parameter of the function to String because I took the number from a TextInput so is already a String.</description>
		<content:encoded><![CDATA[<p>I change the parameter of the function to String because I took the number from a TextInput so is already a String.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edenshaw</title>
		<link>http://www.cgiinteractive.com/blog/2009/05/formatting-numbers-with-commas-in-as3/comment-page-1/#comment-53</link>
		<dc:creator>Edenshaw</dc:creator>
		<pubDate>Mon, 13 Sep 2010 16:45:31 +0000</pubDate>
		<guid isPermaLink="false">http://cgiinteractive.com/blog/?p=134#comment-53</guid>
		<description>First of all thanks for your function it helped me a lot.

The only thing I found that is not working is with a number like this: &quot;1593578642598796.32&quot; because the output will be &quot;1,593,578,642,598,796.30&quot; as you can see, the last part change and it shouldn&#039;t. The problem I found was the casting (sort of speak) of the changing between Number to String. 

When I debug your function, the line: 

var num:String = String(number);

change the number &quot;1593578642598796.32&quot; to &quot;1593578642598796.3&quot; and assigns it to the variable &quot;num&quot; and from that point everything will go wrong.

The only solution I found it was changing the type of parameter of the function, instead of &quot;Number&quot; change it to &quot;String&quot;:

function addCommas( number:String ):String {

and in the line:

var num:String = String(number);

change it to:

var num:String = number;

Perhaps if you believe that the problem is because is a decimal point number, if I try this number &quot;1593578642598799996&quot; the output it will be &quot;1,593,578,642,598,800,000&quot; I know that is some sort of approximation but if what you need is the exact number but with only commas, then this will be a problem. Again, the solution for this is changing the parameter of the function and the line of casting.

P.S.: Sorry for my english and thanks again</description>
		<content:encoded><![CDATA[<p>First of all thanks for your function it helped me a lot.</p>
<p>The only thing I found that is not working is with a number like this: &#8220;1593578642598796.32&#8243; because the output will be &#8220;1,593,578,642,598,796.30&#8243; as you can see, the last part change and it shouldn&#8217;t. The problem I found was the casting (sort of speak) of the changing between Number to String. </p>
<p>When I debug your function, the line: </p>
<p>var num:String = String(number);</p>
<p>change the number &#8220;1593578642598796.32&#8243; to &#8220;1593578642598796.3&#8243; and assigns it to the variable &#8220;num&#8221; and from that point everything will go wrong.</p>
<p>The only solution I found it was changing the type of parameter of the function, instead of &#8220;Number&#8221; change it to &#8220;String&#8221;:</p>
<p>function addCommas( number:String ):String {</p>
<p>and in the line:</p>
<p>var num:String = String(number);</p>
<p>change it to:</p>
<p>var num:String = number;</p>
<p>Perhaps if you believe that the problem is because is a decimal point number, if I try this number &#8220;1593578642598799996&#8243; the output it will be &#8220;1,593,578,642,598,800,000&#8243; I know that is some sort of approximation but if what you need is the exact number but with only commas, then this will be a problem. Again, the solution for this is changing the parameter of the function and the line of casting.</p>
<p>P.S.: Sorry for my english and thanks again</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

