美文网首页
Vue将金额小写转换成大写

Vue将金额小写转换成大写

作者: 第一梯队利群 | 来源:发表于2019-10-23 10:33 被阅读0次
    priceChange(number) {
          var ret = "";
          if (number != "" && number != null && number != "0") {
            var unit = "仟佰拾亿仟佰拾万仟佰拾元角分",
              str = "";
            number += "00";
            var point = number.indexOf(".");
            if (point >= 0) {
              number = number.substring(0, point) + number.substr(point + 1, 2);
            }
            unit = unit.substr(unit.length - number.length);
            for (var i = 0; i < number.length; i++) {
              str +=
                "零壹贰叁肆伍陆柒捌玖".charAt(number.charAt(i)) + unit.charAt(i);
            }
            ret =
              str
                .replace(/零(仟|佰|拾|角)/g, "零")
                .replace(/(零)+/g, "零")
                .replace(/零(万|亿|元)/g, "$1")
                .replace(/(亿)万|(拾)/g, "$1$2")
                .replace(/^元零?|零分/g, "")
                .replace(/元$/g, "元") + "整";
          }
          this.priceText = ret;
       }
    

    相关文章

      网友评论

          本文标题:Vue将金额小写转换成大写

          本文链接:https://www.haomeiwen.com/subject/ievhvctx.html