Created
August 31, 2010 21:07
-
-
Save banterability/559757 to your computer and use it in GitHub Desktop.
Add commas to integers (2000000 -> 2,000,000) in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var intcomma = function(value) { | |
// inspired by django.contrib.humanize.intcomma | |
var origValue = String(value); | |
var newValue = origValue.replace(/^(-?\d+)(\d{3})/, '$1,$2'); | |
if (origValue == newValue){ | |
return newValue; | |
} else { | |
return intcomma(newValue); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment