<?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: Format Currency in Javascript (simplified)</title> <atom:link href="http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/feed/" rel="self" type="application/rss+xml" /><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/</link> <description>web-development</description> <lastBuildDate>Fri, 03 Feb 2012 05:18:27 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>By: James Bone</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-49764</link> <dc:creator>James Bone</dc:creator> <pubDate>Fri, 03 Feb 2012 05:18:27 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-49764</guid> <description>&lt;3</description> <content:encoded><![CDATA[<p>&lt;3</p> ]]></content:encoded> </item> <item><title>By: Lonnon Foster</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-48152</link> <dc:creator>Lonnon Foster</dc:creator> <pubDate>Mon, 02 Jan 2012 23:22:20 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-48152</guid> <description>Thanks for the function. Clean, concise, handles plenty of edge cases. Perfect!</description> <content:encoded><![CDATA[<p>Thanks for the function. Clean, concise, handles plenty of edge cases. Perfect!</p> ]]></content:encoded> </item> <item><title>By: The Button</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-48005</link> <dc:creator>The Button</dc:creator> <pubDate>Sat, 31 Dec 2011 12:17:12 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-48005</guid> <description>Thanks, worked great/right the first time!</description> <content:encoded><![CDATA[<p>Thanks, worked great/right the first time!</p> ]]></content:encoded> </item> <item><title>By: Matthew</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-46252</link> <dc:creator>Matthew</dc:creator> <pubDate>Tue, 29 Nov 2011 18:56:49 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-46252</guid> <description>that last comment didn&#039;t take my if statement.  oh well.</description> <content:encoded><![CDATA[<p>that last comment didn&#8217;t take my if statement.  oh well.</p> ]]></content:encoded> </item> <item><title>By: Matthew</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-46250</link> <dc:creator>Matthew</dc:creator> <pubDate>Tue, 29 Nov 2011 18:51:43 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-46250</guid> <description>total = total.toFixed(2);
var priceArray = /(\d+)\.(\d+)/.exec(total);
var totalDollars = priceArray[1];
var totalCents = priceArray[2];
// add commas
var formattedDollars = &#039;&#039;;
totalDollars = totalDollars.toString();
for(var i=0; i 0) {
formattedDollars += &#039;,&#039;;
}
formattedDollars += totalDollars.substring(i, i+1);
}</description> <content:encoded><![CDATA[<p>total = total.toFixed(2);<br
/> var priceArray = /(\d+)\.(\d+)/.exec(total);<br
/> var totalDollars = priceArray[1];<br
/> var totalCents = priceArray[2];</p><p> // add commas<br
/> var formattedDollars = &#8221;;<br
/> totalDollars = totalDollars.toString();<br
/> for(var i=0; i 0) {<br
/> formattedDollars += &#8216;,&#8217;;<br
/> }<br
/> formattedDollars += totalDollars.substring(i, i+1);<br
/> }</p> ]]></content:encoded> </item> <item><title>By: Les Kendall</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-45622</link> <dc:creator>Les Kendall</dc:creator> <pubDate>Fri, 04 Nov 2011 20:37:33 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-45622</guid> <description>Great little formatting function, works well. Thanks.</description> <content:encoded><![CDATA[<p>Great little formatting function, works well. Thanks.</p> ]]></content:encoded> </item> <item><title>By: Aaron</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-45546</link> <dc:creator>Aaron</dc:creator> <pubDate>Mon, 31 Oct 2011 16:26:02 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-45546</guid> <description>Perfect. Thank you!</description> <content:encoded><![CDATA[<p>Perfect. Thank you!</p> ]]></content:encoded> </item> <item><title>By: Sam</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-43689</link> <dc:creator>Sam</dc:creator> <pubDate>Thu, 28 Jul 2011 15:31:37 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-43689</guid> <description>I have the following function happening onblur, however I would like this to happen onsubmit on two fields only out of the about 10 input fields I have on the form, Can someone help me please, very clueless here, and I can see my problem is so dumb as I cant seem to find anything on forums on the net... please help
function formatCurrency(num) {
num = num.toString().replace(/\$&#124;\,/g,&#039;&#039;);
if(isNaN(num))
num = &quot;0&quot;;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents&lt;10)
cents = &quot;0&quot; + cents;
for (var i = 0; i &lt; Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+&#039;&#039;+
num.substring(num.length-(4*i+3));
return (((sign)?&#039;&#039;:&#039;&#039;) + &#039;&#039; + num + &#039;&#039; + cents);
}</description> <content:encoded><![CDATA[<p>I have the following function happening onblur, however I would like this to happen onsubmit on two fields only out of the about 10 input fields I have on the form, Can someone help me please, very clueless here, and I can see my problem is so dumb as I cant seem to find anything on forums on the net&#8230; please help</p><p>function formatCurrency(num) {<br
/> num = num.toString().replace(/\$|\,/g,&#8221;);<br
/> if(isNaN(num))<br
/> num = &#8220;0&#8243;;<br
/> sign = (num == (num = Math.abs(num)));<br
/> num = Math.floor(num*100+0.50000000001);<br
/> cents = num%100;<br
/> num = Math.floor(num/100).toString();<br
/> if(cents&lt;10)<br
/> cents = &quot;0&quot; + cents;<br
/> for (var i = 0; i &lt; Math.floor((num.length-(1+i))/3); i++)<br
/> num = num.substring(0,num.length-(4*i+3))+&#039;&#039;+<br
/> num.substring(num.length-(4*i+3));<br
/> return (((sign)?&#039;&#039;:&#039;&#039;) + &#039;&#039; + num + &#039;&#039; + cents);<br
/> }</p> ]]></content:encoded> </item> <item><title>By: Sam</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-43685</link> <dc:creator>Sam</dc:creator> <pubDate>Thu, 28 Jul 2011 12:35:49 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-43685</guid> <description>Thanks Alex G, this has worked great for me too, I&#039;m using this function with on blur, I have removed the $ sign to apply to my own currency, however when the form submits, I need the number submitted to be a round number i.e 1,200.89 to be 120089. Can someone help me on how I can make this function happen on two fields when the form is submitted. I hope I am making sense, am very very new to javascript.</description> <content:encoded><![CDATA[<p>Thanks Alex G, this has worked great for me too, I&#8217;m using this function with on blur, I have removed the $ sign to apply to my own currency, however when the form submits, I need the number submitted to be a round number i.e 1,200.89 to be 120089. Can someone help me on how I can make this function happen on two fields when the form is submitted. I hope I am making sense, am very very new to javascript.</p> ]]></content:encoded> </item> <item><title>By: Dcoffey3296</title><link>http://www.selfcontained.us/2008/04/22/format-currency-in-javascript-simplified/comment-page-1/#comment-43615</link> <dc:creator>Dcoffey3296</dc:creator> <pubDate>Mon, 25 Jul 2011 16:31:11 +0000</pubDate> <guid
isPermaLink="false">http://www.selfcontained.us/?p=58#comment-43615</guid> <description>Thanks this was very helpful.  Thanks to Alex G for adding additional elements!</description> <content:encoded><![CDATA[<p>Thanks this was very helpful.  Thanks to Alex G for adding additional elements!</p> ]]></content:encoded> </item> </channel> </rss>
