阿拉伯数字转中国数字

支持转换范围 0~99

  • 输入:num = “10”

  • 输出:’十’

  • 输入:num = “15”

  • 输出:’十五’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const transformNum = (num) => {
const chars = (num + '').split('')
const capitalNum = '零一二三四五六七八九十'
if (num <= 10) {
return capitalNum[num] || num
}
let split = ''
if (num >= 10 && num < 100 && (num % 10 !== 0)) {
split = '十'
}
const str = chars.map(char => {
if (char == 0) char = 10
return capitalNum[char] || ''
}).join(split)
return num < 20 ? str.slice(-2) : str
}