views:

48

answers:

1

I have a BigDecimal field amount which represents money. And I need to print its value in the browser in format like $123.00, $15.50, $0.33.

How can I do that?

(Еhe only simple solution which I see myself is getting floatValue from BigDecimal and then using NumberFormat to make 2 digits presision for the fraction part).

A: 
public static String currencyFormat(BigDecimal n) {
    return NumberFormat.getCurrencyInstance().format(n);
}

It will use your locale to choose your currency symbol. NumberFormat's javadoc

volothamp