Formatting currencies and decimal places
807588Feb 4 2009 — edited Feb 5 2009I'm currently using NumberFormat.getCurrencyInstance() to format numbers as currency. However, one problem I'm having is that I'd like values with no cents to be formatted with no decimal places, and any values with cents to be formatted with the usual 2 decimal places. For example:
17 would be formatted as $17
17.45 would be formatted as $17.45
17.4 would be formatted as $17.40
The last one is the tricky part--I've tried formatter.setMinimumFractionDigits(0), and this works great for the first two cases. But for the last case, the number gets formatted as $17.4.
Basically my problem is I want a number to be formatted with zero or two decimal places and nothing in between. Is there an easy way to do this?
Thanks in advance.