Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function formatMoney (amount, flag=0) {
- const options = {
- style: 'currency',
- currency: 'USD',
- minimumFractionDigits: 2,
- };
- if (flag) {
- // Leave off .00 for whole dollar amounts
- if (amount % 100 === 0) options.minimumFractionDigits = 0;
- }
- const formatter = new Intl.NumberFormat('en-US', options);
- return formatter.format(amount / 100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement