function a(num) {
    const unit = ['', '十', '百', '千', '万', '十万', '百万', '千万', '亿'];
    const counts = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];

    const pre = Math.floor(num / 1000000000);
    const next = num % 1000000000;

    let getfour = (mynum, flag = false) => {
        if(!mynum){return ''}
            let i = 0, str = '';

        while(flag ? i < 9 : mynum > 0 ) {
            count = mynum % 10;
            mynum = Math.floor(mynum / 10);
            str = (count ? counts[count] + unit[i] : str[0] == '零' ? '' : str.length && i ? '零' : '') + str;
            i++;
        }
        return str;
    };

    return pre ? getfour(pre) + '十亿' + getfour(next, true) : getfour(num);
}

标签: JS整数转中文

添加新评论