wood burning stoves 2.0*
The moose likes Java in General and the fly likes custom currency formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "custom currency formatting" Watch "custom currency formatting" New topic
Author

custom currency formatting

fred flintstone
Greenhorn

Joined: Feb 18, 2009
Posts: 1
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
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2162
    
  47
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37897
    
  22
Consider printf or String#format and the % tags as an alternative.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: custom currency formatting
 
Similar Threads
Setting decimalFormatSymbols
Localized Currency formatting issue
Regional settings
How to get List Separator of local system
Number Format problem