This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Format the output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Format the output" Watch "Format the output" New topic
Author

Format the output

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

hello every one
this program compares loans with various interest rates

I've used here the printf method in this line
the problem in the format of this first column of the output
5.000000
5.125000
5.250000
5.375000
5.500000
5.625000
5.750000
5.875000
6.000000
6.125000
6.250000
6.375000
6.500000
6.625000
6.750000
7.000000
7.125000
7.250000
7.375000
7.625000
7.750000
7.875000
8.000000
i want to remove zeros and make the format like this
5%
5.125%
5.25%
....
....
8.0%
thanks


I Hear I Forget, I See I Remember, I Do I Understand.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4087
    
  18

Not an answer to your question, but you really need to know the following:

Never never never ever ever ever *ever* use binary floating point to do calculations with money. Use BigInteger instead.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44449
    
  34
There is something in the Java™ Tutorials; go through "Numbers" and note particularly the links to java.util.Formatter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Format the output
 
It's not a secret anymore!