The java.text.NumberFormat class does this; check out in particular the setMaximumFractionDigits and setMinimumFractionDigits methods. Of course, then you'll have a string, but you can convert it back easily enough. [ September 29, 2005: Message edited by: Ulf Dittmer ]
As Rick points out, you should make a distinction between how the number is stored and how it is displayed. When doing calculations, you should store the value as precisely as possible. However, when you display it, you can use either NumberFormat or, if you can use Java 5.0 features, PrintStream.printf() for the exact formatting you want.