Created
December 17, 2020 15:12
-
-
Save wesleybliss/435b8860671e262dd360709ff67de0a8 to your computer and use it in GitHub Desktop.
Format currency #js
This file contains 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 formatCurrency = (number, currency) => { | |
const options = { | |
minimumFractionDigits: 2, | |
currencyDisplay: 'narrowSymbol', | |
currencySign: 'accounting', | |
} | |
if (currency) { | |
options.style = 'currency' | |
options.currency = currency | |
} | |
return new Intl.NumberFormat(getLocale(), options).format(number) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment