Vue将金额小写转换成大写

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将金额小写转换成大写)