• js helper(hsv/hsb转rgb颜色,uuid,金额小写转大写)


    hsv/hsb转rgb颜色

    //h:[0,360],s:[0,100],v:[0,100]
    
    //return r:[0,256], g:[0,256],b:[0,256]
    
    function hsvtorgb(h, s, v) {
      s = s / 100;
      v = v / 100;
      var h1 = Math.floor(h / 60) % 6;
      var f = h / 60 - h1;
      var p = v * (1 - s);
      var q = v * (1 - f * s);
      var t = v * (1 - (1 - f) * s);
      var r, g, b;
      switch (h1) {
        case 0:
          r = v;
          g = t;
          b = p;
          break;
        case 1:
          r = q;
          g = v;
          b = p;
          break;
        case 2:
          r = p;
          g = v;
          b = t;
          break;
        case 3:
          r = p;
          g = q;
          b = v;
          break;
        case 4:
          r = t;
          g = p;
          b = v;
          break;
        case 5:
          r = v;
          g = p;
          b = q;
          break;
      }
      return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
    }
     
    uuid
    function uuid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
      }
      return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }
     
     
    金额小写转大写
    function changeMoneyToChinese(num: number) {
      if (num == 0) {
        return "零"
      }
      let numString = num.toString()
      
      if (!/^(0|[1-9]d*)(.d+)?$/.test(numString))
        return "数据非法";
      let unit = "仟佰拾亿仟佰拾万仟佰拾元角分", str = "";
      numString += "00";
      let pointIndex = numString.indexOf('.');
      if (pointIndex >= 0)
        numString = numString.substring(0, pointIndex) + numString.substr(pointIndex + 1, 2);
      unit = unit.substr(unit.length - numString.length);
      for (var i = 0; i < numString.length; i++){
        str += '零壹贰叁肆伍陆柒捌玖'.charAt(Number(numString.charAt(i))) + unit.charAt(i);
      }
      return str.replace(/零(仟|佰|拾|角)/g, "零")
          .replace(/(零)+/g, "零")
          .replace(/零(万|亿|元)/g, "$1")
          .replace(/(亿)万|壹(拾)/g, "$1$2")
          .replace(/^元零?|零分/g, "")
          .replace(/元$/g, "元整");
    }
  • 相关阅读:
    Ecshop文件结构(Ecshop二次开发辅助文档)
    Python的Web开发环境搭建
    我的第一个.Net网站
    Windows2008R2安装sqlserver2005远程登陆失败错误18456
    SQLSERVER批量更新根据主键ID字符串
    2009年9月国内与国外浏览器市场粗略对比
    SQL2000与SQL2005下高效分页语句
    开源IIS Rewrite组件IonicIsapiRewriter2.0Releasebin
    C++中的typedef的用法
    关于NP complete
  • 原文地址:https://www.cnblogs.com/brainworld/p/7943204.html
Copyright © 2020-2023  润新知