Skip to content

Instantly share code, notes, and snippets.

@indefinitelee
Created September 13, 2018 17:55
Show Gist options
  • Save indefinitelee/8ae2e6568a6ed7b893dd4b24433734c5 to your computer and use it in GitHub Desktop.
Save indefinitelee/8ae2e6568a6ed7b893dd4b24433734c5 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