Created
May 23, 2020 15:18
-
-
Save chinchang/eb5f8801e3c28bdc209f9ec2970e5f69 to your computer and use it in GitHub Desktop.
Formatting numbers into approximate compact form
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
new Intl.NumberFormat(undefined, { | |
notation: 'compact' | |
}).format(12200); | |
// "12K" | |
new Intl.NumberFormat(undefined, { | |
notation: 'compact' | |
}).format(12534200); | |
// "13M" | |
new Intl.NumberFormat(undefined, { | |
notation: 'compact' | |
}).format(125340); | |
// "125K" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment