Skip to content

Instantly share code, notes, and snippets.

@chinchang
Created May 23, 2020 15:18
Show Gist options
  • Save chinchang/eb5f8801e3c28bdc209f9ec2970e5f69 to your computer and use it in GitHub Desktop.
Save chinchang/eb5f8801e3c28bdc209f9ec2970e5f69 to your computer and use it in GitHub Desktop.
Formatting numbers into approximate compact form
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