UNPKG

tdc-js-modules

Version:

9 lines (8 loc) 346 B
const formatMoney = (n: number | string) => { const t = '.'; const sign = n < 0 ? '-' : ''; const i = String(parseInt((n = Math.abs(Number(n) || 0).toFixed(0)), 10)); const j = i.length > 3 ? i.length % 3 : 0; return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + t); }; export default formatMoney;