Parsing currency into a BigDecimal

This is just a quick snippet for my solution of parsing a String into a BigDecimal object. An explanation of the what and why can be found on my blog.

public static BigDecimal parseCurency(String ammount, Locale loc)
    throws ParseException{
    NumberFormat fmt = NumberFormat.getCurrencyInstance(loc);
    Number nbr = fmt.parse(ammount);
    BigDecimal bd = new BigDecimal(nbr.doubleValue());
    BigDecimal adjusted =
    bd.setScale(
       fmt.getMaximumFractionDigits(),
       BigDecimal.ROUND_HALF_UP);
    return adjusted;
}


Sponsors:

About willCode4Beer