• 将数字转化为汉字


    function toChinesNum(num){
    var changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
    var unit = ["", "十", "百", "千", "万"];
    num = parseInt(num);
    var getWan = (temp) => {
    var strArr = temp.toString().split("").reverse();
    var newNum = "";
    for (var i = 0; i < strArr.length; i++) {
    newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
    }
    return newNum;
    }
    var overWan = Math.floor(num / 10000);
    var noWan = num % 10000;
    if (noWan.toString().length < 4) noWan = "0" + noWan;
    return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
    }

    toChinesNum(12345)

  • 相关阅读:
    今日小结 5.7
    今日小结 5.2
    今日小结 4.30
    今日小结 4.29
    设计模式 笔记1
    第一次找实习
    Java入门 任务表
    今日小结 4.24
    今日小结 4.18
    今日小结 4.17
  • 原文地址:https://www.cnblogs.com/zouyun/p/9646226.html
Copyright © 2020-2023  润新知