jquery格式化数字

$.format(1233443322, 3, ',')

 

js代码:

;(function($) {
$.extend({
format : function(str, step, splitor) {
if(str==null){
str='';
}
str = str.toString();
var len = str.length;

if(len > step) {
var l1 = len%step,
l2 = parseInt(len/step),
arr = [],
first = str.substr(0, l1);
if(first != '') {
arr.push(first);
};
for(var i=0; i<l2 ; i++) {
arr.push(str.substr(l1 + i*step, step));
};
str = arr.join(splitor);
};
return str;
}
});
})(jQuery);

posted on 2016-06-30 19:41  静以修身!  阅读(8194)  评论(0编辑  收藏  举报

导航