function num2cn(n) {
const isLose = n < 0
n = Math.abs(n).toString()
const res = [], len = n.length
for (let i = len; i > 0; i -= 4) {
res.push(NumToChina(n.slice(Math.max(0, i - 4) ,i)))
}
const unit = ['', '万', '亿']
for (let i = 0; i < res.length; i++) {
if (res[i] === '') continue
res[i] += unit[i]
}
isLose && res.push('负')
return res.reverse().join('')
}
function NumToChina(n) {
n = n.toString()
if (n === '0') return '零'
const unit = ['', '十','百', '千']
const number = ['零','一','二','三','四','五','六','七','八','九']
const len = n.length
let res = ''
for (let i = 0; i < len; i++) {
const num = Number(n[i])
if (num !== 0) {
if (n[i - 1] === '0') res += '零'
res += number[num] + unit[len - i - 1]
}
}
if (len === 2 && n[0] === '1') res = res.slice(1)
return res
}