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 Java

Round a double to 2 decimal places

From Java

Round up double to 2 decimal places

From Dev

Rounding double to 2 decimal places returns always 0.0

From Dev

Objective C truncate double value to 2 decimal places

From Dev

seq uses comma as decimal separator

From Dev

Convert a number to a String with exactly 2 decimal places

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

Masked EditText with comma as decimal separator

From Dev

Convert string with thousands (and decimal) separator into double

From Dev

Best way to convert a double to String without decimal places

From Dev

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

From Dev

Convert char array to double using unions with all decimal places

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Dev

Convert string to decimal to always have 2 decimal places

From Dev

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

From Dev

Verify and print double value in 2 decimal places

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

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

From Dev

Convert from 4 decimal places to 2

From Dev

Converting Double to 2 Decimal Places

From Dev

Convert string to decimal to always have 2 decimal places

From Dev

How to get a Double value up to 2 Decimal places

From Dev

Add comma separator to a numbers with 2 decimal points

From Dev

adding 2 decimal places to Convert.ToString

From Dev

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

Related Related

  1. 1

    Round a double to 2 decimal places

  2. 2

    Round up double to 2 decimal places

  3. 3

    Rounding double to 2 decimal places returns always 0.0

  4. 4

    Objective C truncate double value to 2 decimal places

  5. 5

    seq uses comma as decimal separator

  6. 6

    Convert a number to a String with exactly 2 decimal places

  7. 7

    Convert a double to 2 decimal places with comma separator

  8. 8

    Masked EditText with comma as decimal separator

  9. 9

    Convert string with thousands (and decimal) separator into double

  10. 10

    Best way to convert a double to String without decimal places

  11. 11

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

  12. 12

    Convert char array to double using unions with all decimal places

  13. 13

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

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

    Convert string to decimal to always have 2 decimal places

  18. 18

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

  19. 19

    Verify and print double value in 2 decimal places

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

    Convert from 4 decimal places to 2

  24. 24

    Converting Double to 2 Decimal Places

  25. 25

    Convert string to decimal to always have 2 decimal places

  26. 26

    How to get a Double value up to 2 Decimal places

  27. 27

    Add comma separator to a numbers with 2 decimal points

  28. 28

    adding 2 decimal places to Convert.ToString

  29. 29

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

HotTag

Archive