Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complete list of all different Intl.NumberFormats

I'm looking for a complete list of all the different Intl.NumberFormats.

The Intl.NumberFormat page shows 3 different formats.

ja-JP -> "¥123,457"
de-DE -> 123.456,79 €
en-IN -> 1,23,000

Is this all? Or is there more?

like image 473
Peter Avatar asked Jan 16 '18 03:01

Peter


People also ask

What is Intl NumberFormat?

Intl.NumberFormat.prototype.format() Getter function that formats a number according to the locale and formatting options of this Intl.NumberFormat object. Intl.NumberFormat.prototype.formatToParts() Returns an Array of objects representing the number string in parts that can be used for custom locale-aware formatting.

What is number format in Java?

NumberFormat is the abstract base class for all number formats. This class provides the interface for formatting and parsing numbers. NumberFormat also provides methods for determining which locales have number formats, and what their names are. NumberFormat helps you to format and parse numbers for any locale.

What is maximumSignificantDigits?

maximumSignificantDigits. The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.

What is Intl in Javascript?

The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting.


1 Answers

Intl was introduced here https://hacks.mozilla.org/2014/12/introducing-the-javascript-internationalization-api/ with these takeaways:

  1. There's no official list, since "The api is best-effort"
  2. By default, browsers accepts ALL correctly formatted codes (BCP 47 is mentioned and then finds the best fit
  3. You might specify lookup only to disable the best fit algorithm, and then you could get a list of all countries and language codes and that way run through all combinations for a specific browser on a specific OS with a specific list of installed languages but I guess that's not what you want to hear if you're building a web project. But you might want to make use of supportedLocalesOf to have something locally relevant to choose from.
  4. Under the hood browsers typically use ICU or similar

tl;dr: So if you send in your best guess at a valid locale, the best fit algorithm will get you something usable!

Valid locale? According to the documentation and my earlier research, the Intl javascript API expects you to format your locale codes according to BCP 47.

like image 117
Simon B. Avatar answered Oct 12 '22 12:10

Simon B.