Skip to content

Instantly share code, notes, and snippets.

@alpual
Created January 30, 2018 19:38
Show Gist options
  • Save alpual/ae65ecf86e7fb43e38b78c30dde03edd to your computer and use it in GitHub Desktop.
Save alpual/ae65ecf86e7fb43e38b78c30dde03edd to your computer and use it in GitHub Desktop.
// takes a jquery object and replaces the html with formatted currency (USD)
var formatPrices = function($prices) {
if ($prices.length > 0){
jQuery.each($prices, function(){
var value = Number(this.innerHTML);
this.innerHTML= '$' + value.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment