Created
January 20, 2021 19:27
-
-
Save bobdobbalina/c9b39b0bfee86ed1216443e6659105f9 to your computer and use it in GitHub Desktop.
Javascript: Format currency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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