Last active
January 28, 2025 13:14
-
-
Save TheRealOwenRees/dd0915e9e04acfd3b7c23d6be52b3465 to your computer and use it in GitHub Desktop.
Convert a number to a currency with your chose locale and currency type. Use 'undefined' to adjust to the host's locale.
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
| export const numberToCurrency = (value: number | string): string => { | |
| const numericValue = | |
| typeof value === "string" ? Number.parseFloat(value) : value; | |
| return numericValue.toLocaleString(undefined, { | |
| style: "currency", | |
| currency: "EUR", | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment