Skip to content

Instantly share code, notes, and snippets.

@TheRealOwenRees
Last active January 28, 2025 13:14
Show Gist options
  • Select an option

  • Save TheRealOwenRees/dd0915e9e04acfd3b7c23d6be52b3465 to your computer and use it in GitHub Desktop.

Select an option

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.
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