Skip to content

Instantly share code, notes, and snippets.

@andrit
Created December 4, 2018 03:07
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 andrit/1303d3b6da9bc4a6428a8dba729a9571 to your computer and use it in GitHub Desktop.
Save andrit/1303d3b6da9bc4a6428a8dba729a9571 to your computer and use it in GitHub Desktop.

(from WesBos Advanced React and GraphQL course)[https://advancedreact.com/]

export default function(amount) {
  const options = {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: 2,
  };
  // if its a whole, dollar amount, leave off the .00
  if (amount % 100 === 0) options.minimumFractionDigits = 0;
  const formatter = new Intl.NumberFormat('en-US', options);
  return formatter.format(amount / 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment