Created
July 30, 2012 11:43
-
-
Save vstoykov/3206375 to your computer and use it in GitHub Desktop.
Pretty print numbers with thousand delimiter
This file contains 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, delimiter) { | |
/* | |
Original script found here https://gist.github.com/559757 | |
Added optional argument delimiter to choose witch symbol | |
to use for thousand delimiter | |
*/ | |
var origValue = String(value); | |
if (typeof(delimiter) == 'undefined') delimiter = ','; | |
var newValue = origValue.replace(/^(-?\d+)(\d{3})/, '$1'+delimiter+'$2'); | |
if (origValue == newValue){ | |
return newValue; | |
} else { | |
return intcomma(newValue, delimiter); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment