标签:
1 ‘use strict‘; 2 3 var chineseNum = { 4 0: ‘零‘ , 5 1: ‘一‘ , 6 2: ‘二‘, 7 3: ‘三‘, 8 4: ‘四‘, 9 5: ‘五‘, 10 6: ‘六‘, 11 7: ‘七‘, 12 8: ‘八‘, 13 9: ‘九‘ 14 }; 15 var chineseUnit = { 16 0: ‘‘, 17 1: ‘十‘, 18 2: ‘百‘, 19 3: ‘千‘, 20 4: ‘万‘, 21 5: ‘十‘, 22 6: ‘百‘, 23 7: ‘千‘, 24 8: ‘亿‘, 25 9: ‘十‘, 26 10: ‘百‘, 27 11: ‘千‘ 28 }; 29 30 function toChinaNum (num) { 31 var numArr = num.toString().split("").reverse(); 32 var res = []; 33 for(var i = 0; i < numArr.length; i++) { 34 res.push(chineseNum[parseInt(numArr[i])]+chineseUnit[i]); 35 } 36 return res.reverse().join(""); 37 } 38 39 toChinaNum(123847);
标签:
原文地址:http://www.cnblogs.com/friedice/p/4415015.html