Skip to content

Instantly share code, notes, and snippets.

@tjunghans
Created September 1, 2015 06:18
Show Gist options
  • Save tjunghans/9907a15e3ba55da24c68 to your computer and use it in GitHub Desktop.
Save tjunghans/9907a15e3ba55da24c68 to your computer and use it in GitHub Desktop.
function thousands(value) {
var SIZE = 3;
var parts = String(value).split('.');
var number = parts[0];
var dec = parts.length === 2 ? '.' + parts[1] : ''
var formatted = '';
var i;
var len = number.length;
for (i = 0; i < len; i++) {
if (len > SIZE && i > 0 && !((len - i) % SIZE)) {
formatted += '\'';
}
formatted += number[i];
}
return formatted + dec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment