Skip to content

Instantly share code, notes, and snippets.

@d48
Created June 28, 2012 22:22
Show Gist options
  • Save d48/3014374 to your computer and use it in GitHub Desktop.
Save d48/3014374 to your computer and use it in GitHub Desktop.
no cents from format currency
formatCurrency: function(value, noCents) {
if (!isPrice.test(value)) {
return value;
}
noCents = noCents || false;
var precision = 2
, price = parseFloat( Math.abs(value) ).toFixed(precision)
, priceArray = String(price).split('.')
, priceDollars = priceArray[0]
, priceCents = priceArray[1] || null
;
while (priceFormatRegex.test(priceDollars)) {
priceDollars = priceDollars.replace(priceFormatRegex, '$1' + ',' + '$2');
}
return priceDollars + ((priceCents !== null && noCents === false) ? '.' + priceCents : '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment