If for some reason I do not want to use the Internationalization constructors for formatting numbers when it comes to adding commas. Then I will have to look for some other native built in solutions for this sort of thing, or write of find a method that will work okay for most if not all situations when it comes to number formating.
The Intl.NumberFormat constructor can be used to work with language sensitive number formatting. This is what I used to make a quick method for formating money when it comes to having a such a method in one of my utility library projects. This includes money, as well as percent values, as well as a few other options when it comes to styles. Properties can be used to format money in terms of the USD, or any kind of other currency if the right options are set.
The next argument that I give the constructor should be an object, this object should contain a style property with a value of currency. I should also give a currency property to the object and give the ISO 4217 currency code that I want to use, for me this will possibly always be USD.
The returned result then is a formatter, that I can then call and pass a number value. The result that is then returned by the formatter will then be my formated string value that I want.
Another useful feature of this NumberFormat constructor is to use to to format a percent value. This is done more or less the same way as with the currency style, but I just set a percent style rather than currency. I can then pass a number value to the returned formatter and when doing so the number given should be a fraction between and including zero and one.
When making a formating method off of this I might want to have just a few more options and features when it comes to producing the number value to give to the formatter. For example I might want to use it my passing a numerator and denominator value to get a percentage. Also it might be nice to have an option to turn on clamping of a percent value in some situations.
Sometimes I might just want to format a decimal number that refers to something other than money. For these kinds of situations there is a plain decimal style than can be used to format a number. This will give more or less the same effect as the currency style but without the currency symbol append to the output as one might expect. So then the Number Formatter constructor is great not just for money, percent values, and other untis, but any kind of number in general actually when using the decimal style.
I did not get around to covering every little feature of the Intl object in this post, but I wanted to get into the Number Formatter a little at least because that is the one function that will will likely be using the most often in actual projects. If I get some more time to come back ground to this post maybe I will expand this content with a few more examples but I think I covered the most important parts of it that I at least will actually be using.