Skip to content

Instantly share code, notes, and snippets.

@robozevel
Created September 18, 2013 10:04
Show Gist options
  • Save robozevel/6607071 to your computer and use it in GitHub Desktop.
Save robozevel/6607071 to your computer and use it in GitHub Desktop.
Unnecessarily clever number formatting function
// 1234567890 => "1,234,567,890"
function formatNumber(n) {
var a = [], s = String(n), i = l = s.length;
while (i--) a.push(s[i]), i && (l - i) % 3 === 0 && a.push(",");
return a.reverse().join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment