Basically, you create an instance of the DecimalFormat class (in java.text), passing the appropriate Stringpattern to the constructor. Then you call the format method on that instance, passing the value you want formatted.
If you're using Java 1.5, you can use the new printf method in PrintStream (e.g., System.out).
Note the "printf" method, which is taking a floating-point specifier (%f) as an argument along with the float value. Here, the specifier "%3.2f" indicates a number at least 3 characters wide with 2 decimal places.
For details on the specifier, see Formatter. [ September 27, 2005: Message edited by: marc weber ]
Two decimal points makes me think of money. Ok, I drive by the PowerBall billboard on the way to work and think of money most of the morning. Anyhow, using floating point math for money will likely make you unhappy in the long run. Floats are good for very large numbers, like the number of atoms in the sun, but not for precise arithmetic like a checking account. Let us know if you're doing money and we'll throw out some alternative ideas.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi