Intl API Lets JavaScript Format Dates, Numbers and Currencies for Any Locale
Hard-coding number, currency and date formats can break for users in other regions, since conventions differ, such as India's lakh grouping versus the US style. The article explains that JavaScript's built-in Intl API applies locale-specific rules automatically using data browsers already include. It demonstrates Intl.NumberFormat for currencies and Intl.DateTimeFormat for localized dates, including Hindi output. It also covers Intl.RelativeTimeFormat and Intl.ListFormat for phrases like "3 days ago" and grammatically correct lists. The author recommends reusing formatter objects because they are costly to create and always specifying an explicit locale for predictable results.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in