/*
* 金额格式化:
* number:要格式化的数字
* decimals:保留几位小数
* thousandsSep:千分位符号
* tdecPoint:小数点符号
* */
numberFormat(number, decimals = 2, thousandsSep = ',', tdecPoint = '.') {
number = (number + '').replace(/[^0-9+-Ee.]/g, '')
if (number.indexOf(',') > -1) {
return number
}
const n = !isFinite(+number) ? 0 : +number
const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
const sep = typeof thousandsSep === 'undefined' ? ',' : thousandsSep
const dec = typeof tdecPoint === 'undefined' ? '.' : tdecPoint
let s = ''
const toFixedFix = function(n, prec) {
const k = Math.pow(10, prec)
return '' + Math.ceil(n * k) / k
}
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.')
const re = /(-?\d+)(\d{3})/
while (re.test(s[0])) {
s[0] = s[0].replace(re, '$1' + sep + '$2')
}
if ((s[1] || '').length < prec) {
s[1] = s[1] || ''
s[1] += new Array(prec - s[1].length + 1).join('0')
}
return s.join(dec)
},