aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Localized Currency formatting issue" Watch "Localized Currency formatting issue" New topic
Author

Localized Currency formatting issue

Sumit Mishra
Greenhorn

Joined: Mar 25, 2003
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Localized Currency formatting issue
 
Similar Threads
I18N Currency Formatting Issue
Format number
number format
Regional settings
How to get List Separator of local system