5

Followup to My Intl Short Number Post

 1 year ago
source link: https://www.raymondcamden.com/2023/01/10/followup-to-my-intl-short-number-post
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client


Raymond Camden

DevRel at Adobe, Star Wars nerd, Web/Serverless hacker, lover of good beer and good books. Oh, and cats.



January 10, 2023

Followup to My Intl Short Number Post

Followup to My Intl Short Number Post

A few days ago I shared a blog post about using the Intl object in JavaScript to create short, more readable numbers. So for example, instead of 9123456, it would display 9.1M. This was done using the notation option in Intl.NumberFormat. Yesterday I randomly ran into an interesting modification on this using yet another option, compactDisplay.

The compactDisplay option is only used when notation is set to compact. It supports two options, short which is default and what I demonstrated in the previous post, and long.

So given a number, i, you would use it like so:

new Intl.NumberFormat('en-US', { notation:'compact', compactDisplay:'long'}).format(i);

And the result is, well, longer. ;) What's nice though is that it's still a shortened, simpler version. You can see the result here:

Awesome. And if you want to dig deeper into Intl, I recommend the very cool Intl Explorer site. It's an interactive explorer for the Intl spec and covers everything. (If I had paid more attention to it, I would have seen compact sooner!)

Share: Twitter Facebook LinkedIn

Support this Content!

If you like this content, please consider supporting me. You can become a Patron, visit my Amazon wishlist, or buy me a coffee! Any support helps!

Want to get a copy of every new post? Use the form below to sign up for my newsletter.

Webmentions

1 Reply

Polyglot Developer
Reply by Polyglot Developer posted on 1/11/2023 at 1:00 AM
Followup to My Intl Short Number Post raymondcamden.com/2023/01/10/fol…
source

2 Likes and 1 Retweet


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK