daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function formatMoney (amount, flag=0) {
  2.   const options = {
  3.     style: 'currency',
  4.     currency: 'USD',
  5.     minimumFractionDigits: 2,
  6.   };
  7.  
  8.   if (flag) {
  9.       // Leave off .00 for whole dollar amounts
  10.       if (amount % 100 === 0) options.minimumFractionDigits = 0;
  11.   }
  12.  
  13.   const formatter = new Intl.NumberFormat('en-US', options);
  14.  
  15.   return formatter.format(amount / 100);
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top