wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Percentages displayed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Percentages displayed" Watch "Percentages displayed" New topic
Author

Percentages displayed

Collin Grey
Greenhorn

Joined: Jul 04, 2004
Posts: 5
Hi all

how do I show the percentages of items counted in my results pannel?

Eg.

I would like to display the following, obviously variable depending on results:
12.5% Blue
12.5% Grey
25.0% Silver
50.0% Gold

But it only displays:
Blue
Grey
Silver
Gold

Any ideas?

Collin
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
You haven't provided us with enough information. What is your specific problem, what errors are you getting, etc.
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
1. Post your code. We are able to help more if we see what you have (not just verbal description?

2.To get an instance of a class to format numbers in a currency or as a percentage, use the statement


f= NumberFormat.getCurrencyInstance(getLocale());
or


f= NumberFormat.getPercentInstance(getLocale());

Do you know how to use these?


Author and Instructor, my book
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Here is another example to help:



The output from this program is:

47%
Collin Grey
Greenhorn

Joined: Jul 04, 2004
Posts: 5
Thanks I will try it.
Collin Grey
Greenhorn

Joined: Jul 04, 2004
Posts: 5
Thanks I will try it.
 
 
subject: Percentages displayed