1 Replies - 290 Views - Last Post: 29 November 2011 - 09:31 PM Rate Topic: -----

#1 Newbe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-November 11

Trying to display values from an array in a GUI in Currency format

Posted 29 November 2011 - 09:13 PM

I am new to Java and I have project due where I need to display the objects of an Array (inventory list) in a GUI one product at a time. I have everything functioning the way I need to other than I can not figure how to return the double values in dollar and cent format, I get too many decimal places.
I have been over the text book chapters several times and cannot find one example that sheds any light on this issue, in fact the text book has been less than helpful on this entire GUI project.
I have attached a zip file that contains all of my classes. Where I am having difficulty is on lines 177,178,180,181, and 183 of the DVDdisplay class.
I have tried to import the Currency Utility and change my String.format() to currency.format() and this returns a GUI void of any array info. I would greatly appreciate any suggestions that anyone may have.

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to display values from an array in a GUI in Currency format

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Trying to display values from an array in a GUI in Currency format

Posted 29 November 2011 - 09:31 PM

Try the String class format() method something like

double amount = 3.14159;
String str = String.format("Amount: $ %5.2f", amount);

sould put in str "Amount: $ 3.14"

This post has been edited by pbl: 29 November 2011 - 09:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1