Format Currency
In case you want to implement a function to format currency instead of just using toLocaleString() then, you can use the following.
const formatCurrency = (amt) => { if (!amt && amt !== 0) return ''; const sign = (Math.abs(amt) === amt ? '' : '-'); let amtStr = Math.abs(amt).toFixed(2); for (let i = amtStr.length - 6; i > 0; i -= 3) { amtStr = `${amtStr.substring(0, i)},${amtStr.substring(i, amtStr.length)}`; } return `${sign}$${amtStr}`; }; console.log(formatCurrency(123121000));
Output
$123,121,000.00
Format Date
const formatDate = (date) => { const d = new Date(date); return `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()}`; }; console.log(formatDate('2018-03-01T10:00:00Z'));
Output
3/1/2018