Vaadin 8 Grid BigDecimal Valuesdisplay Issue

BigDecimal values in Grid displaying like “0E-8” how can I print in plain string ?

or how can I user bigdecimal method toPlainString(), because I am setting Items to Grid by setItems() method and grid prints all data.

BigDecimal values not displaiying in good format please suggest what to do ?

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



Hope that helps!

39901.png
39902.png

Hi,

Some big decimal fees display as it is but some fields not displaying in plain string format.

please see attached image

Hey. I can’t sadly find any attached images. Can you try attaching it again?

Attached please check.
40921.png