function util(){
this.currency = function (v, Format, n, ct) {
if (typeof (v) == 'number') {
n = n || 2;
ct = ct || 0;
var number = v;
var number = number.toFixed(n);
var number = this.cuter(number, ct);
return Format + number;
}
}
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基础包