/**
* 将数字转换成中文数字
* @param num
* @returns {string}
*/
export const toChinese=(num) => {
let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
let unit = ['', '十', '百', '千', '万']
num = parseInt(num)
let getWan = (temp) => {
let strArr = temp.toString().split('').reverse()
let newNum = ''
let newArr = []
strArr.forEach((item, index) => {
newArr.unshift(item === '0' ? changeNum[item] : changeNum[item] + unit[index])
})
let numArr = []
newArr.forEach((m, n) => {
if (m !== '零') numArr.push(n)
})
if (newArr.length > 1) {
newArr.forEach((m, n) => {
if (newArr[newArr.length - 1] === '零') {
if (n <= numArr[numArr.length - 1]) {
newNum += m
}
} else {
newNum += m
}
})
} else {
newNum = newArr[0]
}
return newNum
}
let overWan = Math.floor(num / 10000)
let noWan = num % 10000
if (noWan.toString().length < 4) {
noWan = '0' + noWan
}
return overWan ? getWan(overWan) + '万' + getWan(noWan) : getWan(num)
}
(1)目录
![](https://i-blog.csdnimg.cn/blog_migrate/06734923b65b2a3032b6d032af0448d9.png)
(2)引用
![](https://i-blog.csdnimg.cn/blog_migrate/70fafd5c62c22ee7d1fbda6c64120e2c.png)
(3)调用
![](https://i-blog.csdnimg.cn/blog_migrate/3c873ae0dcd7396d4fd2dc5d4fa68985.png)