Skip to content

Instantly share code, notes, and snippets.

@nottsknight
Created December 28, 2012 11:51
Show Gist options
  • Save nottsknight/4397083 to your computer and use it in GitHub Desktop.
Save nottsknight/4397083 to your computer and use it in GitHub Desktop.
Right-aligned currency formatting for Java
/**
* Method to format a BigDecimal for printing as an amount of currency. Only works for locales
* where the currency symbol is placed before the amount.
* @param n the value to format
* @returns the formatted String
*/
public String formatCurrency(BigDecimal n) {
String symbol = Currency.getInstance(Locale.getDefault()).getSymbol();
String value = new DecimalFormat("#,###.00").format(n);
return symbol.concat(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment