function util(){
//字符串千分符
this.cuter = function (v, n) {
if (typeof (v) == 'string' || typeof (v) == 'number') {
if (n <= 0) { return v; }
n = n || 3;
var str = String(parseFloat(v));
var strAry = str.split('.');
var float = {
pref: '',
num: '',
point: '',
nextf: ''
}
if (strAry[1]) {
float.point = '.';
float.nextf = strAry[1];
}
float.pref = strAry[0].match(/^[+/-]/) || '';
strAry[0] = strAry[0].replace(/^[+/-]/, '');
var numAry = strAry[0].split('');
var kn = [];
var count = n;
for (var i = numAry.length - 1; i > -1; i--) {
kn.unshift(numAry[i]);
count--;
if (count == 0 && i > 0) {
kn.unshift(',');
count = n;
}
}
float.num = kn.join('');
return float.pref + float.num + float.point + float.nextf;
}
}
}
var g=new util();
想用更多的方法请打开JavaScript基础包