实现代码

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;
    }

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐