Formatting Numbers with the Built-In Intl Object in JavaScript
The Intl object stands for International which is used for formatting number, dates and other types for multiple contries (and formats like different currencies). It also has some other functionality that I will not be discussing here. Anyways, this object can do number formatting across different currencies without having to use a library or much code. For example:
console.log(Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(number1)); // $19,342.99 console.log(Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' }).format(number1)); // £19,342.99 console.log(Intl.NumberFormat('cmn-CN', { style: 'currency', currency: 'CNY' }).format(number1)); // CN¥ 19,342.99 console.log(Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 3, maximumFractionDigits: 3 }).format(number1)); // $19,342.987
The first string is a locale which is the language followed by the country that the language is being used in. The valid language codes and country codes can be found here. The list for the 3 letter currency codes can be found here.
This is supported in all modern browsers, but note that Android Webview which is used in Android Hybrid Apps only supports the NumberFormat that I talked about and not other Intl constructors.
Github Location https://github.com/Jacob-Friesen/obscurejs/blob/master/2018/intl.js















