PDA

View Full Version : Grid NumberColumn Decimal places



Solitaer
18 Jan 2016, 12:30 AM
Hi,

i want to format a grid Number Column.

The field in the model ist float.

Now i want to format the number like this:

52 = 52
52,4= 52,4
52,123456789=52,123456789

i try this:

0.##########

that shows me

52,123456789=52,123456789
but
52 = 52,

Plz Help

gishmo
20 Jan 2016, 3:55 AM
you can try something like this:

if (youNumber % 1 == 0)

to check if the number has a part behind the decimal point or not and depending on the result use different number formatters.

Solitaer
20 Jan 2016, 5:03 AM
I Dont use a numberFormatter. its a NumberColumn in a Grid with Format.

gishmo
20 Jan 2016, 5:14 AM
You can always override a Grid cell using this code:

final NumberFormat number = NumberFormat.getFormat("0.00");
changeCol.setCell(new AbstractCell<Double>() {
@Override
public void render(Context context, Double value, SafeHtmlBuilder sb) {
String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
String v = number.format(value);
sb.appendHtmlConstant("<span " + style + ">" + v + "</span>");
}
});

That's the approach I would give a try.

Pankaj Kumar M
28 Mar 2016, 1:51 AM
grid = ColdFusion.Grid.getGridObject("gridName");
cm = grid.getColumnModel();
var formatAmt = Ext.util.Format.numberRenderer('00,00,00,00,00,000.00');
cm.setRenderer(column number, formatAmt);
grid.reconfigure(grid.getStore(),cm);