千分位转数字,数字转千分位
<script>
class strNumSwitch {
// 千分转数字
static toNum = (param) => {
let num = param
if (`${param}`.includes(',')) {
num = param.replace(/(,*)/g, '')
}
if (isNaN(Number(num))) {
num = 0
}
return Number(num)
}
// 数字转千分
static toStr = (param) => {
const str = param.replace(/(,*)/g, '')
const num = `${str}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
return num
}
}
</script>