Created
August 23, 2012 07:55
-
-
Save craiga/3434036 to your computer and use it in GitHub Desktop.
formatInt
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
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