码迷,mamicode.com
首页 > 其他好文 > 详细

将英文数字转化为中文

时间:2015-04-10 17:23:57      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!