{header : "金额",
width:100,
dataIndex : 'amount',
renderer: amountFormat
},
/**金额格式*/
function amountFormat(v){
v = (Math.round((v*100-0)*1))/100;
v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.'),
whole = ps[0],
sub = ps[1] ? '.'+ ps[1] : '.00',
r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
//if(v.charAt(0) == '-'){
// return '-$' + v.substr(1);
//}
return v;
}
----------------------------------------------------------------------
如果去掉注释的三行,负数的金额会前面加$符号。
width:100,
dataIndex : 'amount',
renderer: amountFormat
},
/**金额格式*/
function amountFormat(v){
v = (Math.round((v*100-0)*1))/100;
v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.'),
whole = ps[0],
sub = ps[1] ? '.'+ ps[1] : '.00',
r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
//if(v.charAt(0) == '-'){
// return '-$' + v.substr(1);
//}
return v;
}
----------------------------------------------------------------------
如果去掉注释的三行,负数的金额会前面加$符号。