The moose likes Beginning Java and the fly likes Formatting as a percent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formatting as a percent" Watch "Formatting as a percent" New topic

Formatting as a percent

Zach Spoelstra

Joined: Feb 19, 2002
Posts: 2
Howdy...Nice board ya got here
OK. I am working on a program for class and I cant get my double variable to properly format as a percent. We were told to use the NumberFormat class and the getPercentInstance method. This is what I am using now and it keeps truncating the decimal portion of my number.
Here is my code:

I am guessing there is just something simple that I am missing here
[ February 19, 2002: Message edited by: Zach Spoelstra ]
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Do you have access to the API documentation? (Javadocs)? If so, you could just look up the NumberFormat class and see the API methods there and probably solve this problem yourself.
I just looked it up really quickly and there are two methods that might be useful:

Hope this helps!

SCJP 1.4
Zach Spoelstra

Joined: Feb 19, 2002
Posts: 2
Actually I have looked extensively at the API and I couldn't for the life of me figure out how to use some of those. I'll give them a shot and report back.
I agree. Here's the link:
subject: Formatting as a percent
It's not a secret anymore!