views:

335

answers:

1

I have a GWT project in which I need to manually specify currency, number and datetime formats. These customizations include specifying the currency symbols, grouping seperator, decimal seperator, negative number formats etc. What would be the best way to accomplish this?

Should I use the GWT NumberFormat class? NumberFormat makes extensive use of the GWT internationalization constructs like the Constants interface etc. If you therefore specify a custom number format mask, it will still look at the current locale and use those monetary symbols, decimal symol and thousand separators, as is specified in the late-bound and internationalized 'NumberFormat' instance.

My question is: how would you accomplish this? Would you re-implement NumberFormat's functionality? Would you derive from it and use the protected constructor and pass it in some kind of custom NumberConstants instance that you created yourself? How about getting the i18n NumberConstants instance, and using that to populate your own instance and override only what you want?

How would you approach this problem?

+1  A: 

I have used NumberFormat.getFormat(String format) for custom currency formatting (removing "US" before the $ sign).

In my application I put the result into public constant. I have stored the "format" argument in i18n resource bundle as well as all UI specific strings.

nomad
I ended up doing something similar. Had to have all kinds of weird hacks but it works ok now.
Pieter Breed