SOURCE

console.log(ToString(123));
function ToString(n) {
  //判断数据是否大于0
  if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)){
      return "";
  }
  let unit = "千百十亿千百十万千百十个";
  let str = "";
  n += "";
  // 如果是小数,截取小数点前面的位数
  var indexpoint = n.indexOf('.');
  // 若为小数,截取需要使用的unit单位
  if (indexpoint >= 0){
    n = n.substring(0, indexpoint) + n.substr(indexpoint+1, 2);
  }
  // 若为整数,截取需要使用的unit单位
  unit = unit.substr(unit.length - n.length);
  for (var i=0; i < n.length; i++){
    str += "零一二三四五六七八九".charAt(n.charAt(i)) + unit.charAt(i);  //遍历转化为大写的数字
  }
  // 替换掉数字里面的零字符,得到结果
  return str.replace(/零(个)/g, "").replace(/(个)+/g, "");
}
console 命令行工具 X clear

                    
>
console