前端将数字0~10转化成汉字一~十
前端将数字0~10转化成汉字一~十
·
实现代码
convertToChinese(number) {
const chineseNumbers = ["一", "二", "三", "四", "五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十"];
const stringNumber = number.toString();
let chineseString = "";
for (let i = 0; i < stringNumber.length; i++) {
const digit = parseInt(stringNumber[i]);
chineseString += chineseNumbers[digit] || "";
}
return chineseString;
}
更多推荐
已为社区贡献3条内容
所有评论(0)