Skip to content

Instantly share code, notes, and snippets.

@anandsunderraman
Created June 24, 2013 19:34
Show Gist options
  • Save anandsunderraman/5852834 to your computer and use it in GitHub Desktop.
Save anandsunderraman/5852834 to your computer and use it in GitHub Desktop.
Regular Expression to Format Currency In Javascript
function formatCurrency(amount)
{
//truncate the amount to 0 decimals
//for every digit that is followed by 3 digits and a word boundary
//add a comma
amount = amount.toFixed(0).replace(/(\d)(?=(\d{3})+\b)/g, "$1,");
return amount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment