Created
December 28, 2012 11:51
-
-
Save nottsknight/4397083 to your computer and use it in GitHub Desktop.
Right-aligned currency formatting for Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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