They should print themselves correctly without any modifications. I created this code:
Bean:
[code]
public class BigDecimalBean {
private BigDecimal num;
public BigDecimalBean(BigDecimal num) {
this.num = num;
}
public BigDecimal getNum() {
return num;
}
public void setNum(BigDecimal num) {
this.num = num;
}
}
[/code]View code:
List<BigDecimalBean> list = Arrays.asList(
new BigDecimalBean(new BigDecimal("12.4")),
new BigDecimalBean(new BigDecimal("13.2")),
new BigDecimalBean(new BigDecimal("105")));
Grid<BigDecimalBean> grid = new Grid<>();
grid.setItems(list);
grid.addColumn(BigDecimalBean::getNum).setCaption("The number");
And it printed itself nicely. See attached screenshot BigDecimalInGrid.png.
To customize how a Grid prints a certain type of data, you should use Renderers. A renderer is applied to columns and takes in any type of data and converts it to a String, and then back from String to type if needed. You can do it from scratch by implementing the interface Renderer or the abstract class AbstractRenderer, but there is already a collection of many renderers free for use. NumberRenderer sounds like the thing that fits you, as BigDecimal is an implementation of Number. Here’s a code sample:
Grid.Column<BigDecimalBean, BigDecimal> column = grid.addColumn(BigDecimalBean::getNum);
column.setCaption("The number");
NumberFormat nf = NumberFormat.getInstance();
column.setRenderer(new NumberRenderer("$%.5f"));
The code is otherwise the same as earlier but row 7 in the previous example is replaced with this snippet. Here we give the column a NumberRenderer with the formatString: “$%.5f” which says that put a dollar sign in front and print out with five decimals always.
Added a screenshot with the renderer as well. withRenderer.png