Last active
October 21, 2015 03:26
-
-
Save luofei2011/9331142fbad724a75644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
function getCode(num) { | |
num = (num + '').split(''); | |
var map = {0: '', 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九', 10: '十'}; | |
var _map = {0: '', 1: '十', 2: '百', 3: '千', 4: '万'}; | |
var now; | |
var index = 0; | |
var re = []; | |
while((now = num.pop())) { | |
if (+now) { | |
re.unshift(map[now] + _map[index]); | |
} | |
else if (index) { | |
re.unshift('零'); | |
} | |
index++; | |
} | |
return re.join('').replace(/^一十/, '十').replace(/零+/, '零').replace(/零$/, ''); | |
} | |
// angular封装filter | |
angular.mobule('app').filter('toCN', function () { | |
var filter = function (num) { | |
num = (num + '').split(''); | |
var map = {0: '', 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九', 10: '十'}; | |
var _map = {0: '', 1: '十', 2: '百', 3: '千', 4: '万'}; | |
var now; | |
var index = 0; | |
var re = []; | |
while((now = num.pop())) { | |
if (+now) { | |
re.unshift(map[now] + _map[index]); | |
} | |
else if (index) { | |
re.unshift('零'); | |
} | |
index++; | |
} | |
return re.join('').replace(/^一十/, '十').replace(/零+/, '零').replace(/零$/, ''); | |
}; | |
return filter; | |
}); | |
``` | |
``` | |
// 用法 | |
<div>{{test | toCH}}</div> | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment