Created
March 12, 2020 11:59
-
-
Save ashour/2fd9f17bf0bed89581532484dfcbf39d 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 formatWithThousandsSeparator(num) { | |
let numAsString = num.toString(); | |
let characters = numAsString.split("").reverse(); | |
let parts = []; | |
for (let i = 0; i < characters.length; i += 3) { | |
let part = characters.slice(i, i + 3).reverse().join(""); | |
parts.unshift(part); | |
} | |
return parts.join(","); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment