I'm trying to use the new Javascript internationalization API, and would like to know if there is a way to get the decimal and thousands (grouping) separator for a Intl.NumberFormat
instance?
There is a resolvedOptions
method on the object, but that does not provide the symbols.
In case anybody's wondering, then for en-US, these would be a comma ,
and period .
, such as in 1,000.00
.
If nothing else, as a trick solution (that doesn't pass the Turkey Test; see comment), you can use the output of
toLocaleString()
to determine information about number formatting in a locale. For the current locale, for example:The same trick can be used for currency formatting, using e.g.
(12345.6789).toLocaleString("en-GB", { style: "currency" })
.I'm afraid ECMA-402 standard does not define the API that let you access separators. There is also another problem - at the moment the adoption of ECMA-402 is not as wide as we wish.
Therefore for the time being, if I were you I would look to something like CLDR JSON bindings or iLib which apparently provides these information through LocaleInfo's
getDecimalSeparator()
andgetGroupingSeparator()
functions.BTW. iLib seems to use CLDR as a source of information.