<?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; php</title>
	<atom:link href="http://blog.imfreshfromtheoven.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.imfreshfromtheoven.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 06 Oct 2011 23:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Javascript:number_format()</title>
		<link>http://blog.imfreshfromtheoven.com/2009/04/javascriptnumber_format/</link>
		<comments>http://blog.imfreshfromtheoven.com/2009/04/javascriptnumber_format/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 14:36:42 +0000</pubDate>
		<dc:creator>admin</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; : UPDATE : There was a bug in the code. The zeros to the left in the decimals (if there was any) were erased. UPDATE 2 : There was a second bug, when the number was under 0. Fixed now]]></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 class="brush: jscript; title: ; notranslate">
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&amp;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 &amp;lt; decimals) for (var iRight=right.length; iRight &amp;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 <img src='http://blog.imfreshfromtheoven.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.imfreshfromtheoven.com/2009/04/javascriptnumber_format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

