标签:script count let toc next 级别 ++ ext class
const toChineseNum = (num) => { const unit = [‘‘, ‘十‘, ‘百‘, ‘千‘] const counts = [‘零‘, ‘一‘, ‘二‘, ‘三‘, ‘四‘, ‘五‘, ‘六‘, ‘七‘, ‘八‘, ‘九‘] const pre = Math.floor(num / 10000) const next = num % 10000 let getfour = (mynum, flag = false) => { if(!mynum){return ‘‘} let i = 0, str = ‘‘ while(flag ? i < 4 : 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) } console.log(toChineseNum(59900670))
完成将 toChineseNum, 可以将数字转换成中文大写的表示,处理到万级别,例如 toChineseNum(12345),返回 一万二千三百四十五
标签:script count let toc next 级别 ++ ext class
原文地址:http://www.cnblogs.com/love314159/p/7651410.html