Skip to content

Instantly share code, notes, and snippets.

@indefinitelee
Created September 13, 2018 17:56
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 indefinitelee/15c4bbd8e1f8544648626323f3493ac8 to your computer and use it in GitHub Desktop.
Save indefinitelee/15c4bbd8e1f8544648626323f3493ac8 to your computer and use it in GitHub Desktop.
SereneExemplaryConference created by indefinitelee1 - https://repl.it/@indefinitelee1/SereneExemplaryConference
const dollarFormat = (amount, defaultValue) => {
console.log(amount)
if (!amount)
return defaultValue;
const result = `${parseFloat(amount).toFixed(2)}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
console.log(result)
if (isNaN(result))
return defaultValue
else
return '$' + result;
}
const cpm = 44444.44
const otherDollarFormat = (amount, defaultValue) => amount ? `$${parseFloat(amount).toFixed(2)}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',') : defaultValue;
dollarFormat(cpm, '$0' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment