Format Number in Currency using javascript

Now you can convert your number in currency format using the below function.

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');
}

Share and Enjoy

  • Facebook
  • Twitter
  • Google Plus
  • Live
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
  • Instapaper
  • FriendFeed

Comments

  1. Hello, Neat post. There’s a problem together with your site in web explorer, could check this? IE still is the market leader and a huge component of folks will leave out your excellent writing because of this problem.

  2. Thank you for some other wonderful post. The place else may anybody get that kind of info in such a perfect method of writing? I’ve a presentation next week, and I’m at the search for such information.

  3. Tremendous issues here. I am very glad to look your post. Thank you a lot and I am having a look ahead to touch you. Will you please drop me a mail?

  4. I will right away take hold of your rss as I can’t in finding your e-mail subscription hyperlink or newsletter service. Do you’ve any? Please allow me understand so that I may just subscribe. Thanks.