Created
October 15, 2019 17:33
-
-
Save pigeonfresh/d13702a40a2330397cbdf6f7fd92f594 to your computer and use it in GitHub Desktop.
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
const formatNumber = number => (num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')) | |
console.info(formatNumber(2665)) // 2,665 | |
console.info(formatNumber(102665)) // 102,665 | |
console.info(formatNumber(111102665)) // 111,102,665 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment