Created
January 30, 2018 19:38
-
-
Save alpual/ae65ecf86e7fb43e38b78c30dde03edd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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