您的位置:首页 > 其它

Ext gridPanel ColumnModel中钱的格式设置

2015-08-12 15:08 337 查看
{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;
  }
----------------------------------------------------------------------



如果去掉注释的三行,负数的金额会前面加$符号。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: