• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

custom currency formatting

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I'm trying to do some custom currency formatting. There are some bugs/outdated data in the current java locale currency formatting results. I could update my locale database using http://userguide.icu-project.org/icu4j-locale-service-provider#TOC-Using-ICU4J-Locale-Service-Provider

but I just want to be able to format some currencies by hand using either NumberFormat or DecimalFormat.

Here is my test class:

This results in:
result:124.523.423.434,50

So if you notice, that for result, the currency symbol is missing. How come the DecimalFormatSymbols doesn't make the currency symbol appear when I set it?

Another question is, what if I wanted to make the currency symbol appear AFTER the number?

Thanks,
Eric
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want the currency symbol to display you have a few choices, such as:

1. Use the NumberFormat.getCurrencyInstance() method to get a formatter that handles currencies.
2. Supply your own pattern which outputs the currency symbol.

Another question is, what if I wanted to make the currency symbol appear AFTER the number?


If you are using option 1 above, I would imagine the currency formatter will put the symbol in an appropriate location for that currency. If you want to change that behaviour then I believe you will have to supply your own pattern.
If you are using option 2 then you are supplying a pattern so you can put the symbol wherever you want

For details on setting your own pattern see the DecimalFormat classes API docs.
 
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider printf or String#format and the % tags as an alternative.
 
reply
    Bookmark Topic Watch Topic
  • New Topic