Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created February 2, 2012 16:38
Show Gist options
  • Save jashkenas/1724464 to your computer and use it in GitHub Desktop.
Save jashkenas/1724464 to your computer and use it in GitHub Desktop.
// Format a number into a dollar string.
Card.prototype.formatDollars = function(num) {
var chars = (Math.round(num) + '').split('').reverse();
var result = [];
while (chars.length > 3) {
result = result.concat(chars.slice(0, 3));
result.push(',');
chars = chars.slice(3);
}
result = result.concat(chars);
return '$' + result.reverse().join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment