• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Localized Currency formatting issue

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
    Bookmark Topic Watch Topic
  • New Topic