Contents
Intro
Number Format
Currency Format
Units Format
Summary
Intro
Reducing dependencies that you ship wit...
For further actions, you may consider blocking this person and/or reporting abuse
Wish we had something similar for dates π€£
It won't translate into other languages but this element from GitHub will help with common date display tasks
jordanfinners.dev/blogs/5-github-e...
I've just checked and there is also this developer.mozilla.org/en-US/docs/W...
Which would do this for dates! π
This is neat! π
.toLocaleDateString
I knew
Intl
was awesome, but man, looking at the docs of it, I see so many functions that I've written myself before.It depends on the size and the importance of the project and what versions of browsers that project needs to keep supporting. If we have a project that thousands or millions of users use in a daily basis, then most likely we'll have to deal with old browsers that won't have built-in support for
Intl.NumberFormat
API.In a perfect universe where all people would have browsers that would support latest features, that would be awesome; but if we ditch backward compatibility and don't deal with missing APIs, then we'll end up with user's frustration, countless hours of debugging dealing with such issues and users moving away to other apps/platforms that will be able to see the actual numbers and not errors or empty strings.
Also, making applications using a native feature if it's available and fallback to a library if the feature is not available, will create inconsistency regarding data formatting and presenting.
If we have statistics regarding the userbase and the browsers they're using, the team can make conclusions and decide which minimum browser versions the platform/app will support and always detect these features and if not available display messages to the users that they have obsolete browsers/platforms and they need to update.
PS: Never use floats to store currency values, always use integers to strore the prices as cents!
PS2: caniuse.com/NumberFormat is always a nice way to check for features and browsers compatibility so we can have some clues of what we're going to deal with regarding obsolete but still used browsers/platforms.
That looks pretty cool. I did not know about
Intl.NumberFormat
. Thanks a lot for this informative post. πIt's so awesome! Thanks for the article :)
Thank you! Your tip is very helpful.
Thanks for this amazing information and API. Keep up the hard work π₯ π
Oh my gosh. I almost cry hahahaha this is so good. I have spent months of my life writing code to solve multiple problems related to number rounding.
Nice article :)
Hey Jordan, Awesome post! I deal with having to format stuff like this all of time at work so I'm going to give Intl.NumberFormat a try. Thanks for the tip ππ»
give the .toLocaleString function a chance... it's Intl shortkey
Cool. If only there was also an API to format date- OMG There is! :D
Yesss! Just got to watch out for Safari on some of these still, unfortunately.
Thank you
Really helpful
Thanks
I didn't know about this one, thanks!
This is great until you work on legacy code which uses node 12 and you can't update because of other reasons.
Would love to hear the reasons ππ
Or you just call .toLocaleString on Number it supports the whole Intl formatting options...