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 ]