如何把阿拉伯数字转为汉字呢,上代码
<template>
<view>第{{day}}天</view>
</template>
<script>
export default {
data() {
return {
day:""
}
},
onLoad() {
this.day=this.getNum(12)
},
methods: {
getNum(number) {
let zhArray = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
let baseArray = ['', '十', '百', '千', '万', '十', '百', '千', '亿', '十', '百', '千', '万'];
let string = String(number)
.split('')
.reverse()
.map((item, index) => {
item = Number(item) == 0 ? zhArray[Number(item)] : zhArray[Number(item)] + baseArray[index];
return item;
})
.reverse()
.join('');
string = string.replace(/^一十/, '十');
string = string.replace(/零+/, '零');
return string;
}
}
}
</script>