Skip to content

Instantly share code, notes, and snippets.

@bobdobbalina
Created January 20, 2021 19:27
Show Gist options
  • Save bobdobbalina/c9b39b0bfee86ed1216443e6659105f9 to your computer and use it in GitHub Desktop.
Save bobdobbalina/c9b39b0bfee86ed1216443e6659105f9 to your computer and use it in GitHub Desktop.
Javascript: Format currency
const toCurrency = (n, curr, LanguageFormat = undefined) =>
Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
toCurrency(123456.789, 'EUR'); // €123,456.79 | currency: Euro | currencyLangFormat: Local
toCurrency(123456.789, 'USD', 'en-us'); // $123,456.79 | currency: US Dollar | currencyLangFormat: English (United States)
toCurrency(322342436423.2435, 'JPY'); // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local
toCurrency(322342436423.2435, 'JPY', 'fi'); // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment