Convert a double to 2 decimal places with comma separator

pmaingi

In my view i have the below code

IndexedContainer icLoaded = new IndexedContainer(); 
icLoaded.removeAllItems();  
icLoaded.removeAllContainerFilters();

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 {

        Class.forName(dbsettings.dbDriver);

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

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

        while (rs.next()) {

            passTable.addItem(rs.getString("item_id"));

            passTable.getContainerProperty(rs.getString("item_id"),
                    "Average Cost").setValue(rs.getDouble("average_cost"));

How can i convert the below

 passTable.getContainerProperty(rs.getString("item_id"),
                    "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 .

 passTable.getContainerProperty(rs.getString("item_id"),
                    "Average Cost").setValue(numberFormat.format(rs.getDouble("average_cost")));
Elliott Frisch

You call NumberFormat#format(double) and save the formatted double as a String, because a double is a primitive value and it has no inherent formatting -

NumberFormat numberFormat = new DecimalFormat("#,###.00");
double val = 1000.12;
System.out.println(numberFormat.format(val));

Output is

1,000.12

Edit

You need to change this

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

to

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

How to convert a double to a string with 2 decimal places?

From Java

Round a double to 2 decimal places

From Dev

Converting Double to 2 Decimal Places

From Dev

Add comma separator to a numbers with 2 decimal points

From Dev

Convert string with thousands (and decimal) separator into double

From Dev

How to convert floating point decimal separator from dot to comma in Javascript

From Java

Round up double to 2 decimal places

From Dev

Verify and print double value in 2 decimal places

From Dev

How to convert point to comma for any number of decimal places

From Dev

Format a number with comma separators and round to 2 decimal places in Python 2?

From Dev

Convert a number to a String with exactly 2 decimal places

From Dev

Convert from 4 decimal places to 2

From Dev

adding 2 decimal places to Convert.ToString

From Dev

Scala: Print Double with decimal and thousands seperator and 2 decimal places

From Dev

Scala: Print Double with decimal and thousands seperator and 2 decimal places

From Dev

Masked EditText with comma as decimal separator

From Dev

seq uses comma as decimal separator

From Dev

Jquery/Javascript Regular expression to filter decimal numbers with comma, 13 int places and 2 decimal places

From Dev

Best way to convert a double to String without decimal places

From Dev

Convert char array to double using unions with all decimal places

From Dev

Convert string to decimal to always have 2 decimal places

From Dev

Convert string to decimal to always have 2 decimal places

From Dev

Format a decimal with comma as decimal separator and without thousands separator

From Dev

Objective C truncate double value to 2 decimal places

From Dev

Rounding double to 2 decimal places returns always 0.0

From Dev

Format, 2 decimal places for double and 0 for integer in java

From Dev

How to ensure that my double output is ONLY 2 decimal places?

From Dev

How to get a Double value up to 2 Decimal places

Related Related

  1. 1

    Convert a double to 2 decimal places with comma separator

  2. 2

    How to convert a double to a string with 2 decimal places?

  3. 3

    Round a double to 2 decimal places

  4. 4

    Converting Double to 2 Decimal Places

  5. 5

    Add comma separator to a numbers with 2 decimal points

  6. 6

    Convert string with thousands (and decimal) separator into double

  7. 7

    How to convert floating point decimal separator from dot to comma in Javascript

  8. 8

    Round up double to 2 decimal places

  9. 9

    Verify and print double value in 2 decimal places

  10. 10

    How to convert point to comma for any number of decimal places

  11. 11

    Format a number with comma separators and round to 2 decimal places in Python 2?

  12. 12

    Convert a number to a String with exactly 2 decimal places

  13. 13

    Convert from 4 decimal places to 2

  14. 14

    adding 2 decimal places to Convert.ToString

  15. 15

    Scala: Print Double with decimal and thousands seperator and 2 decimal places

  16. 16

    Scala: Print Double with decimal and thousands seperator and 2 decimal places

  17. 17

    Masked EditText with comma as decimal separator

  18. 18

    seq uses comma as decimal separator

  19. 19

    Jquery/Javascript Regular expression to filter decimal numbers with comma, 13 int places and 2 decimal places

  20. 20

    Best way to convert a double to String without decimal places

  21. 21

    Convert char array to double using unions with all decimal places

  22. 22

    Convert string to decimal to always have 2 decimal places

  23. 23

    Convert string to decimal to always have 2 decimal places

  24. 24

    Format a decimal with comma as decimal separator and without thousands separator

  25. 25

    Objective C truncate double value to 2 decimal places

  26. 26

    Rounding double to 2 decimal places returns always 0.0

  27. 27

    Format, 2 decimal places for double and 0 for integer in java

  28. 28

    How to ensure that my double output is ONLY 2 decimal places?

  29. 29

    How to get a Double value up to 2 Decimal places

HotTag

Archive