const NUM_CN_MAP = { 0: '', 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九', }
const MID_CN_MAP = { 0: '', 1: '十', 2: '百', 3: '千', }
const WAN_CN_MAP = { 0: '', 1: '万', 2: '亿', }
const numToCn = num => { let temp = num let ans = '' let mid = 0 let wanMid = 0 while (temp > 0) { let temp2 = temp % 10 ans = MID_CN_MAP[mid] + NUM_CN_MAP[temp2] + ans
let tempMid = (mid + 1) % 4 if (!tempMid) wanMid++
ans = WAN_CN_MAP[wanMid] + ans mid = tempMid
temp = Math.floor(temp / 10) }
return ans }
console.log(numToCn(1222233))
|