Skip to content

Instantly share code, notes, and snippets.

@gucheen
Created January 26, 2021 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gucheen/998da4d437abf91576b7fc6d47a4d44b to your computer and use it in GitHub Desktop.
Save gucheen/998da4d437abf91576b7fc6d47a4d44b to your computer and use it in GitHub Desktop.
morden-elegant-way-to-format-currency-in-js
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