<?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/"
	>

<channel>
	<title>Fresh from the oven &#187; format</title>
	<atom:link href="http://blog.imfreshfromtheoven.com/tag/format/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.imfreshfromtheoven.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 20 Jul 2010 20:49:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript:number_format()</title>
		<link>http://blog.imfreshfromtheoven.com/2009/04/17/javascriptnumber_format/</link>
		<comments>http://blog.imfreshfromtheoven.com/2009/04/17/javascriptnumber_format/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 14:36:42 +0000</pubDate>
		<dc:creator>I'm FFTO</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.imfreshfromtheoven.com/?p=52</guid>
		<description><![CDATA[Here&#8217;s a little javascript to format numbers like the PHP function &#8220;number_format&#8221; :

function number_format (number, decimals, dec_point, thousands_sep){
	if (isNaN(number) &#124;&#124; number=='') number = 0;

	var decimals 		= decimals != undefined ? decimals : 2,
		dec_point		= dec_point != undefined ? dec_point : '.',
		thousands_sep	= thousands_sep != undefined ? thousands_sep : ' ',
		negative		= number&#60;0;

	if (negative) number *= -1;

	var left 	= [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little javascript to format numbers like the PHP function &#8220;number_format&#8221; :</p>
<blockquote>
<pre>function number_format (number, decimals, dec_point, thousands_sep){
	if (isNaN(number) || number=='') number = 0;

	var decimals 		= decimals != undefined ? decimals : 2,
		dec_point		= dec_point != undefined ? dec_point : '.',
		thousands_sep	= thousands_sep != undefined ? thousands_sep : ' ',
		negative		= number&lt;0;

	if (negative) number *= -1;

	var left 	= parseInt(number, 10),
		right	= Math.round(parseFloat(number.toString().replace(/^\d+./, '0.')) * Math.pow(10, decimals));

	left  = left.toString().split('').reverse().join('')
			.match(/\d{3}|\d{1,2}/g)
			.join(thousands_sep)
			.split('').reverse().join('');

	right = (right / Math.pow(10,decimals)).toString().replace(/^\d+./, '').toString();

	if (right.length &lt; decimals) for (var iRight=right.length; iRight &lt; decimals; iRight++) right += '0';

	return (negative?'-':'')+left+dec_point+right;
}</pre>
</blockquote>
<p><strong>UPDATE : </strong>There was a bug in the code. The zeros to the left in the decimals (if there was any) were erased.<br />
<strong>UPDATE 2 :</strong> There was a second bug, when the number was under 0. Fixed now :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.imfreshfromtheoven.com/2009/04/17/javascriptnumber_format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
