Created
September 1, 2015 06:18
-
-
Save tjunghans/9907a15e3ba55da24c68 to your computer and use it in GitHub Desktop.
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 thousands(value) { | |
var SIZE = 3; | |
var parts = String(value).split('.'); | |
var number = parts[0]; | |
var dec = parts.length === 2 ? '.' + parts[1] : '' | |
var formatted = ''; | |
var i; | |
var len = number.length; | |
for (i = 0; i < len; i++) { | |
if (len > SIZE && i > 0 && !((len - i) % SIZE)) { | |
formatted += '\''; | |
} | |
formatted += number[i]; | |
} | |
return formatted + dec; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment