<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title></title>
	<atom:link href="http://sacah.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sacah.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 29 Apr 2011 02:46:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sacah.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title></title>
		<link>http://sacah.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sacah.wordpress.com/osd.xml" title="" />
	<atom:link rel='hub' href='http://sacah.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Javascript Formatting Numbers, Prices or Amounts</title>
		<link>http://sacah.wordpress.com/2011/04/29/javascript-formatting-numbers-prices-or-amounts/</link>
		<comments>http://sacah.wordpress.com/2011/04/29/javascript-formatting-numbers-prices-or-amounts/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 02:35:03 +0000</pubDate>
		<dc:creator>sacah</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sacah.wordpress.com/?p=26</guid>
		<description><![CDATA[After looking around at many different number formatting scripts, I figured surely the joy of regular expressions could do this is far fewer lines of code, so off I set and below is my creation. First is the two line function, below that I have put each statement on a new line for ease of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sacah.wordpress.com&amp;blog=22624211&amp;post=26&amp;subd=sacah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After looking around at many different number formatting scripts, I figured surely the joy of regular expressions could do this is far fewer lines of code, so off I set and below is my creation. First is the two line function, below that I have put each statement on a new line for ease of explaining what/how it does its formatting.</p>
<p><pre class="brush: jscript; light: true;">
function formatNumber(number) {
  number=number+'';
  return number.replace(/[^\d\.\-]/g, '').replace(/(\.\d{2})[\W\w]+/g, '$1').split('').reverse().join('').replace(/(\d{3})/g, '$1,').split('').reverse().join('').replace(/^([\-]{0,1}),/, '$1').replace(/(\.\d)$/, '$1'+'0').replace(/\.$/, '.00');
}
</pre></p>
<p>Some examples</p>
<p><pre class="brush: jscript; toolbar: false;">
formatNumber(-1234.56);
formatNumber(1234567.890);
formatNumber(123.3);
formatNumber('4423897544352423434');
</pre></p>
<p>Output</p>
<p><pre class="brush: jscript; toolbar: false;">
-1,234.56
1,234,567.89
123.30
4,423,897,544,352,423,434
</pre></p>
<p>Explination</p>
<p><pre class="brush: jscript;">
function formatNumber(number) {
  number=number+'';
  return number.replace(/[^\d\.\-]/g, '')
    .replace(/(\.\d{2})[\W\w]+/g, '$1')
    .split('')
    .reverse()
    .join('')
    .replace(/(\d{3})/g,'$1,')
    .split('')
    .reverse()
    .join('')
    .replace(/^([\-]{0,1}),/, '$1')
    .replace(/(\.\d)$/, '$1'+'0')
    .replace(/\.$/, '.00');
}
</pre></p>
<p><pre class="brush: jscript; light: true;">number=number+'';</pre><br />
Simply converts number into a string.</p>
<p><pre class="brush: jscript; light: true;">return number.replace(/[^\d\.\-]/g, '')</pre><br />
Replaces anything that isn&#8217;t a digit (\d), a full stop (\.) or a minus sign (\-) with an empty string (&#8221;). This will get rid of dollar signs, already existing formatting like commas etc.</p>
<p><pre class="brush: jscript; light: true;">.replace(/(\.\d{2})[\W\w]+/g, '$1')</pre><br />
Detects the first 2 digits after the first full stop (\.\d{2}) and captures this info. Then detects all characters after the first two digits till the end of the line [\W\w]+. All this gets replaced with the first match. eg 100.1234 (\.\d{2}) matches .12 and [\W\w]+ matches 34. Then .1234 gets replaced with .12</p>
<p><pre class="brush: jscript; light: true;">.split('')</pre><br />
Split the string into an Array.</p>
<p><pre class="brush: jscript; light: true;">.reverse()</pre><br />
Reverse the array.</p>
<p><pre class="brush: jscript; light: true;">.join('')</pre><br />
Join the array back into a String.</p>
<p><pre class="brush: jscript; light: true;">.replace(/(\d{3})/g,'$1,')</pre><br />
Match groups of 3 digits (\d{3}), and replace them with the matches text followed by a comma $1,.</p>
<p><pre class="brush: jscript; light: true;">.split('')</pre><br />
Split the string into an Array again.</p>
<p><pre class="brush: jscript; light: true;">.reverse()</pre><br />
Reverse the array again.</p>
<p><pre class="brush: jscript; light: true;">.join('')</pre><br />
Join the array back to a string.</p>
<p><pre class="brush: jscript; light: true;">.replace(/^([\-]{0,1}),/, '$1')</pre><br />
Matches 0 to 1 occurrences of a minus sign ([\-]{0,1}) at the start of a line (^), followed by a comma. This gets replaced by the first match, which is either an empty string or a minus sign. -,123 becomes -123.</p>
<p><pre class="brush: jscript; light: true;">.replace(/(\.\d)$/, '$1'+'0')</pre><br />
Matches a single digit following a full stop (\.\d) at the end of the line ($), and replaces this with the full stop and digit plus a 0. 1.1 becomes 1.10</p>
<p><pre class="brush: jscript; light: true;">.replace(/\.$/, '.00');</pre><br />
Matches a full stop at the end of the line, and replaces it with .00</p>
<p>If you have any questions or find any bugs, leave me a comment and let me know.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sacah.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sacah.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sacah.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sacah.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sacah.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sacah.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sacah.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sacah.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sacah.wordpress.com&amp;blog=22624211&amp;post=26&amp;subd=sacah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sacah.wordpress.com/2011/04/29/javascript-formatting-numbers-prices-or-amounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/beed5ef01b03e8e97edf07338768a31f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sacah</media:title>
		</media:content>
	</item>
		<item>
		<title>First post FTW</title>
		<link>http://sacah.wordpress.com/2011/04/29/21/</link>
		<comments>http://sacah.wordpress.com/2011/04/29/21/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 01:26:14 +0000</pubDate>
		<dc:creator>sacah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sacah.wordpress.com/?p=21</guid>
		<description><![CDATA[So after lots of issues with the whole migration from Google Apps to their new system I found out that my Blogger account can&#8217;t be migrated, along with a few other services! This is quite annoying, and was the final nail in the coffin of my using Blogger, I&#8217;ve used it for quite a while, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sacah.wordpress.com&amp;blog=22624211&amp;post=21&amp;subd=sacah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So after lots of issues with the whole migration from Google Apps to their new system I found out that my Blogger account can&#8217;t be migrated, along with a few other services! This is quite annoying, and was the final nail in the coffin of my using Blogger, I&#8217;ve used it for quite a while, it&#8217;s always been simple and highly customisable, though after all these years just hasn&#8217;t kept up with other blogging services.</p>
<p>So here I am on WordPress, a very different beast that Blogger. First impressions are it&#8217;s extremely restrictive from a customisation point unless you want to fork out money. On the plus it has some of the nice features like code syntax highlighting and easy posting of images/videos, so hopefully that makes up for the pay point down falls. You can&#8217;t have everything for free (-:</p>
<p>If you&#8217;re still looking for my old posts, they will still be available on <a href="http://sacah.blogspot.com">sacah.blogspot.com</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sacah.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sacah.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sacah.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sacah.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sacah.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sacah.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sacah.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sacah.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sacah.wordpress.com&amp;blog=22624211&amp;post=21&amp;subd=sacah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sacah.wordpress.com/2011/04/29/21/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/beed5ef01b03e8e97edf07338768a31f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sacah</media:title>
		</media:content>
	</item>
	</channel>
</rss>
