Skip to content

Instantly share code, notes, and snippets.

@craiga
Created August 23, 2012 07:55
Show Gist options
  • Save craiga/3434036 to your computer and use it in GitHub Desktop.
Save craiga/3434036 to your computer and use it in GitHub Desktop.
formatInt
function formatInt(num) {
num = parseInt(num);
str = new String(num);
if(str.length > 4) {
var formatted = "";
do {
var lastChar = str.length;
formatted += "," + str.slice(lastChar - 3);
str = str.slice(0, lastChar - 3);
} while(str.length > 3);
str = str + formatted;
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment