GeeCON Prague 2014*
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formatting as a percent" Watch "Formatting as a percent" New topic
Author

Formatting as a percent

Zach Spoelstra
Greenhorn

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
Bartender

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:
NumberFormat.setMaximumFractionDigits(int);
NumberFormat.setMinimumFractionDigits(int);

Hope this helps!


Rob
SCJP 1.4
Zach Spoelstra
Greenhorn

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.
Thanks
 
GeeCON Prague 2014
 
subject: Formatting as a percent