Created
January 26, 2021 09:50
-
-
Save gucheen/998da4d437abf91576b7fc6d47a4d44b to your computer and use it in GitHub Desktop.
morden-elegant-way-to-format-currency-in-js
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 amountFormatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'CNY' }) | |
/** | |
* 1234567.12 to 1,234,567.12 | |
* @param amount | |
*/ | |
export const formatAmount = (amount: number): string => { | |
if (typeof amount === 'undefined') { | |
return '' | |
} | |
return amountFormatter.format(amount).substr(3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment