Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Localized Currency formatting issue

 
Sumit Mishra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using JDK1.2.2. My objective is to format a double number in currency format based on the locale of the user e.g. input is 123456789 and if the user locale is US then output should be 123,456,789 and if the locale is IN then output should be 12,34,56,789. Here i don't want the currency symbol to be prefixed to the number.
Locale lCurrentLocale = Locale.US;
NumberFormat lNumberFormat =
NumberFormat.getCurrencyInstance(lCurrentLocale);
DecimalFormat lDecimalFormat =(DecimalFormat) lNumberFormat;
DecimalFormatSymbols lDecimalFormatSymbols = lDecimalFormat.getDecimalFormatSymbols() ;
String lCurrencySymbol = lDecimalFormatSymbols.getCurrencySymbol();
System.out.println("Currency Symbol (OLD) :: " + lCurrencySymbol);
//tried to set some other symbol as the currency symbol
lDecimalFormatSymbols.setCurrencySymbol("%");
lDecimalFormat.setDecimalFormatSymbols(lDecimalFormatSymbols);
lDecimalFormatSymbols = lDecimalFormat.getDecimalFormatSymbols() ;
lCurrencySymbol = lDecimalFormatSymbols.getCurrencySymbol();
System.out.println("Currency Symbol (NEW) :: " + lCurrencySymbol);
System.out.println("Decimal format (WITH PERCENT) :: " + lDecimalFormat.format(Double.parseDouble("123456789.123456789")) );
Output of the above code is:
Currency Symbol (OLD) :: $
Currency Symbol (NEW) :: %
Decimal format (WITH PERCENT) :: $123,456,789.12
Expected output:
Decimal format (WITH PERCENT) :: %123,456,789.12

Any reason why this is not happening??Is there any alternative to the above approach??
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic