Convert a double to 2 decimal places with comma separator

In my view i have the below code

IndexedContainer icLoaded = new IndexedContainer();

icLoaded.addContainerProperty(“Average Cost”, Double.class, null);
In the model i have the below code

public IndexedContainer DoFetchstockCodesTable(String passedSQL,
IndexedContainer passTable, String CustomsaleQuerry) {

try {


    final Connection conn = DriverManager.getConnection(
            new Home().GiveMeSessionDB(), dbsettings.dbUsername,
    final Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery(passedSQL.trim());

    while ( {


                "Average Cost").setValue(rs.getDouble("average_cost"));

How can i convert the below

“Average Cost”).setValue(rs.getDouble(“average_cost”));
to display a number with 2 decimal places separated by a comma separator like 1,000.12 using

NumberFormat numberFormat = new DecimalFormat(“#,###.00”);
When i use the below , nothing gets displayed .

“Average Cost”).setValue(numberFormat.format(rs.getDouble(“average_cost”)));


First of all, your property type is Double:

icLoaded.addContainerProperty("Average Cost", Double.class, null);

But the formatter sets String values. Strange that you don’t get an IllegalArgumentException.
Setting the type to String should solve this, but then the sorting of that column will be sorted String-wise, which is not desirable.

So, a better option would be to let the container contain Double for that property id, but add a Converter to the table so that only the visual representation changes:

        passTable.setConverter("Average cost", new Converter<String, Double>() {

            public Double convertToModel(String value,
                    Class<? extends Double> targetType, Locale locale)
                    throws {
                if (value == null) {
                    return null;
                return Double.valueOf(value);

            public String convertToPresentation(Double value,
                    Class<? extends String> targetType, Locale locale)
                    throws {
                if (value == null) {
                    return null;
                return numberFormat.format(value);

            public Class<Double> getModelType() {
                return Double.class;

            public Class<String> getPresentationType() {
                return String.class;

And as a little side note, I assume you want the format “#,##0.00” instead of “#,###.00” in case of zero values

Best regards,

Thanks Johan for a great solution . I want it in this format #,###.00. Cheers.