<?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: Algorithm for adding leading zeros</title>
	<atom:link href="http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/feed/" rel="self" type="application/rss+xml" />
	<link>http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/</link>
	<description>Life in a Flash</description>
	<lastBuildDate>Fri, 22 Jan 2010 06:40:18 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ed</title>
		<link>http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/comment-page-1/#comment-992</link>
		<dc:creator>Ed</dc:creator>
		<pubDate>Fri, 22 Jan 2010 06:40:18 +0000</pubDate>
		<guid isPermaLink="false">http://shang-liang.com/blog/?p=143#comment-992</guid>
		<description>Adding a little bit to @Fernandos post. You need to add 1 to the number of zeros to join to make it come out to the correct number. I also made it so that the number of zeros to add defaults to 1.

public static function addLeadingZero(n:int, numZeros:int = 1):String 
{
	return (new Array(numZeros + 1).join(&#039;0&#039;)) + n as String;
}</description>
		<content:encoded><![CDATA[<p>Adding a little bit to @Fernandos post. You need to add 1 to the number of zeros to join to make it come out to the correct number. I also made it so that the number of zeros to add defaults to 1.</p>
<p>public static function addLeadingZero(n:int, numZeros:int = 1):String<br />
{<br />
	return (new Array(numZeros + 1).join(&#8217;0&#8242;)) + n as String;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mozart Petter</title>
		<link>http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/comment-page-1/#comment-816</link>
		<dc:creator>Mozart Petter</dc:creator>
		<pubDate>Tue, 14 Jul 2009 13:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://shang-liang.com/blog/?p=143#comment-816</guid>
		<description>I think that a good solution is this:

function addLeadingZeros(n:Number, q:Number):String
		{
			return Math.pow(10, q - n.toString().length).toString().substr(1) + n;
		}

Without the unnecessary loop. :)

Cheers</description>
		<content:encoded><![CDATA[<p>I think that a good solution is this:</p>
<p>function addLeadingZeros(n:Number, q:Number):String<br />
		{<br />
			return Math.pow(10, q &#8211; n.toString().length).toString().substr(1) + n;<br />
		}</p>
<p>Without the unnecessary loop. <img src='http://shang-liang.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 5566</title>
		<link>http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/comment-page-1/#comment-775</link>
		<dc:creator>5566</dc:creator>
		<pubDate>Fri, 03 Jul 2009 02:01:48 +0000</pubDate>
		<guid isPermaLink="false">http://shang-liang.com/blog/?p=143#comment-775</guid>
		<description>@Fernando, I will blame the programmer whoever tries to pass &quot;-1&quot; in to add zeros in front of it. It&#039;s pointless to use uint either. It&#039;ll end up as a very big integer. 

Anyway, very cool algorithm. Smarter than mine, definitely!</description>
		<content:encoded><![CDATA[<p>@Fernando, I will blame the programmer whoever tries to pass &#8220;-1&#8243; in to add zeros in front of it. It&#8217;s pointless to use uint either. It&#8217;ll end up as a very big integer. </p>
<p>Anyway, very cool algorithm. Smarter than mine, definitely!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fernando</title>
		<link>http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/comment-page-1/#comment-774</link>
		<dc:creator>Fernando</dc:creator>
		<pubDate>Thu, 02 Jul 2009 18:35:06 +0000</pubDate>
		<guid isPermaLink="false">http://shang-liang.com/blog/?p=143#comment-774</guid>
		<description>You arguments should be unsigned int or otherwise you will end up with smth like: &quot;000-10&quot;.

My try would be:

function addZero(n:uint, numZeros:uint):String{
	return (new Array(numZeros).join(&quot;0&quot;)) + n;
}

Cheers!</description>
		<content:encoded><![CDATA[<p>You arguments should be unsigned int or otherwise you will end up with smth like: &#8220;000-10&#8243;.</p>
<p>My try would be:</p>
<p>function addZero(n:uint, numZeros:uint):String{<br />
	return (new Array(numZeros).join(&#8221;0&#8243;)) + n;<br />
}</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fabbrikk</title>
		<link>http://shang-liang.com/blog/algorithm-for-adding-leading-zeros/comment-page-1/#comment-772</link>
		<dc:creator>fabbrikk</dc:creator>
		<pubDate>Thu, 02 Jul 2009 10:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://shang-liang.com/blog/?p=143#comment-772</guid>
		<description>Hi, I think you have forgot the return statement.

function addZero(n:int, numZeros:int = 1):String {
      var str:String = n + &quot;&quot;;
      while (str.length&lt;numZeros+1)
      {
            str = &quot;0&quot; + str;
      }
      return str;
}</description>
		<content:encoded><![CDATA[<p>Hi, I think you have forgot the return statement.</p>
<p>function addZero(n:int, numZeros:int = 1):String {<br />
      var str:String = n + &#8220;&#8221;;<br />
      while (str.length&lt;numZeros+1)<br />
      {<br />
            str = &#8220;0&#8243; + str;<br />
      }<br />
      return str;<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
