0

I am using a listview and want to format the text as money. I am getting the numerical data from a cursor and loading it into a number of textboxes, i.e.

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            R.layout.list_item_sales_order, 
            null,  //was mCursor 
            new String[]{MyobiliseData.Columns_TempOrders.SALES_ITEM_DESCRIPTION
            ,MyobiliseData.Columns_TempOrders.SALES_ITEM_QTY
            ,MyobiliseData.Columns_TempOrders.SALES_ITEM_PRICE_EXGST
            ,MyobiliseData.Columns_TempOrders.SALES_ITEM_TOTAL_INCGST},
            new int[] {R.id.liItemDescription, R.id.liItemQty, R.id.liItemPrice, R.id.liTotal}
            );
    theListView.setAdapter(adapter);

Can I format the text as money, e.g. $10.56 rather than 10.56 which shows up now?

thanks

Anton

WaterBoy
  • 697
  • 3
  • 13
  • 35

2 Answers2

1

The right way to format a currency value is:

NumberFormat.getCurrencyInstance(Locale.US).format(YOUR_CURRENCY_VALUE))

Hope this helps.

Arun George
  • 18,352
  • 4
  • 28
  • 28
  • Sorry I wasn't clear with my question - what exactly do i format. It is a listview so where can I apply any text formatting? – WaterBoy Jun 25 '12 at 10:29
  • `Can I format the text as money, e.g. $10.56 rather than 10.56 which shows up now?` The above post is an answer to this question of yours. So identify the text which gives you the value of currency(eg 10.56) and use the above method to get it converted to the Currency format of the specified Locale(eg for Locale.US the output will be $10.56). – Arun George Jun 25 '12 at 10:36
0

I think Number format should do it.

 DecimalFormat df = new DecimalFormat("\u00A4##,##"); //$
 System.out.println("Pattern: " + df.toPattern() + " -> " + df.format(value));
Nuno Gonçalves
  • 6,202
  • 7
  • 46
  • 66