Vue中阿拉伯数字与汉字的相互转换
numberfilter (num) {
const changeNum = [‘零’, ‘一’, ‘二’, ‘三’, ‘四’, ‘五’, ‘六’, ‘七’, ‘八’, ‘九’] // changeNum[0] = “零”
const unit = [’’, ‘十’, ‘百’]
num = parseInt(num)
const getWan = (temp) => {
const strArr = temp.toString().split(’’).reverse()
let newNum = ‘’
for (var i = 0; i < strArr.length; i++) {
newNum = (i == 0 && strArr[i] == 0 ? ‘’ : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? ‘’ : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum
}
return newNum
}
const overWan = Math.floor(num / 100)
let noWan = num % 100
if (noWan.toString().length < 2) noWan = ‘0’ + noWan
let strr = (overWan ? getWan(overWan) + ‘百’ + getWan(noWan) : getWan(num))
if(strr.split(’’)[0] == ‘一’){
let showNum = “”;
if(strr == ‘一’){
showNum = strr.substring(0);
}else{
showNum = strr.substring(1);
}
return “第”+showNum+“条”
}else{
let showNum = overWan ? getWan(overWan) + ‘百’ + getWan(noWan) : getWan(num);
return “第”+showNum+“条”
}
},