There is a good question on rounding decimals in Java here. But I was wondering how can I include the trailing zeros to display prices in my program like: $1.50, $1.00
T
While others answers are perfectly valid (especially duffymo's one), you have a much bigger problem than formatting the display. You are actually using a totally wrong type for a money amount which is a discrete value. Instead of a double
, you should really consider using a java.lang.BigDecimal.
(EDIT: ... or a well implemented Money class as duffymo pointed out in a comment, for example classes from JScience's monetary module or the more recent Joda-Money - which has still to be released as an official version.)