PDA

View Full Version : Formatting numbers < 1



charlie17
4 Sep 2011, 2:05 PM
Forgive me, I've searched on this but not found anything right on point.

I have values coming into a grid column, most of which are less than 1, and all of which have 2-3 decimal places. No matter how values are passed in or I tweak the numbercolumn format, Ext 4 formats them with the 0 in front of the decimal.

For example if the # passed in is .123 I would like it shown in the grid as .123 not as 0.123.

As another example if the # passed in is 1.23 I would like it shown in the grid as 1.230.

Any ideas?

Thanks

danguba
4 Sep 2011, 11:26 PM
Try to add this renderer to column
renderer: function(value, p, r){
return value.toFixed(3)
}

vasm
6 Sep 2011, 1:36 AM
Not a standard (good) way to do it but this may help.


renderer: function(val){
val = val.toFixed(3);
val = val.toString();
return val.replace(/^0*/, '');
}

But the column should be of type string, coz number will always display a 0 infront of decimal.

charlie17
10 Sep 2011, 9:52 AM
Thanks guys, but neither of these approaches worked. Any other ideas? Again the primary need is to format a # that comes through as 0.123 to show up in a grid as .123

vasm
10 Sep 2011, 11:14 AM
I hope you are not giving any xtype to the column. The above rendered without any xtype should work.

charlie17
12 Sep 2011, 5:03 AM
Thanks vasm - that did work. Frankly I'm not sure what I was missing before, but it's working now. Thanks again