wood burning stoves 2.0
The moose likes Java in General and the fly likes Localized Currency formatting issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Localized Currency formatting issue" Watch "Localized Currency formatting issue" New topic

Localized Currency formatting issue

Sumit Mishra

Joined: Mar 25, 2003
Posts: 1
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 =
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 = 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??
I agree. Here's the link: http://aspose.com/file-tools
subject: Localized Currency formatting issue
It's not a secret anymore!