阿拉巴数字转换中文数字

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/smalCat/article/details/81707486

SectionToChinese(section){

let chnNumChar= ["零","一","二","三","四","五","六","七","八","九"];

let chnUnitSection= ["","万","亿","万亿","亿亿"];

let chnUnitChar= ["","十","百","千"];

  let strIns = '', chnStr = '';

  let unitPos = 0;

  let zero = true;

  while(section > 0){

    let v = section % 10;

    if(v === 0){

      if(!zero){

        zero = true;

        chnStr = chnNumChar[v] + chnStr;

      }

    }else{

      zero = false;

      strIns = chnNumChar[v];

      strIns += chnUnitChar[unitPos];

      chnStr = strIns + chnStr;

    }

    unitPos++;

    section = Math.floor(section / 10);

  }

  return chnStr;

}

猜你喜欢

转载自blog.csdn.net/smalCat/article/details/81707486