Rounding numbers in the table


I want to ask that is the easiest way to round numbers in the table. I set data to the table from container.


Some of the item properties values are floats, for example “100.50”, but I want them to be shown in the table rounded, should be “101”. What’s the easiest way of doing that?

Thank you :wink:


one way would be to override the method

protected String formatPropertyValue(Object rowId, Object colId, Property property)

and return the value as a String, formatted like you see fit. You can do the formatting e.g. only for one column, based on the colId parameter and call the super class’ method for the rest.

If you are using Vaadin 7 you could also define a custom converter for rounded doubles

table.setConverter(propertyId, new RoundingDoubleConverter());

The advantage would be that you could re-use the converter in textfields or other parts of your application later. If the only place you need to round your numbers is that table, Teppo’s solution is probably easier.

Read more about creating your own converters here: