• 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

How to create a custom currency format

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have some code that sets a number's format to match the currency symbol of certain countries.

However, I have one instance where I want to set a custom currency character set. Basically, if I do this:

NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

Then if I call that numberFormat, I can format a number to look like "$275"

But, how do I create a numberformat that would literally display like "(TTT)$275"? I'm currently using the Taiwan Locale as a placeholder, but I'd like to know how to make a custom format.

Current code is below:



Thank you for your time!
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure whether it answers your specific question, but you might have a look at the API documentation for the Currency class, starting from where it says

Oracle wrote:Users can supersede the Java runtime currency data by means of the system property java.util.currency.data.

 
Robert Van Liew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I'm not sure whether it answers your specific question, but you might have a look at the API documentation for the Currency class, starting from where it says

Oracle wrote:Users can supersede the Java runtime currency data by means of the system property java.util.currency.data.



Looking at this:

https://docs.oracle.com/javase/8/docs/api/java/util/Currency.html

I don't think that gives me information on what I'm trying to do - that cryptic explanation of the 'system' property, which I'm not even sure how to access, shows 3 values in the example that don't look anything like a currency symbol or formatting string.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't say anything about currency codes as far as I can see either. But I'm not clear on what you're trying to do. Are you trying to make a customized NumberFormat for an existing currency, or are you trying to make a new currency (not in ISO 4217 or whatever it is)?
 
Robert Van Liew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:It doesn't say anything about currency codes as far as I can see either. But I'm not clear on what you're trying to do. Are you trying to make a customized NumberFormat for an existing currency, or are you trying to make a new currency (not in ISO 4217 or whatever it is)?



I could do either.

This 'TTT' currency is actually conceptually representing US Dollars, but for a second entity in this application (rather than the 'main' business entity), so all I need to do is differentiate the display of money numbers from this second entity, using a custom format.

I am open to taking an existing currency, such as Taiwan, and hijacking it's behavior so that it displays like '(TTT)$' instead of the normal 'NT$' formatting of Taiwan.

Or, I could also as you suggest try creating a new currency/format, and using that

Whatever's easiest/best, I'm fine with using. But I don't know how to do either.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe it's more of an intrusive solution than what you were looking for, but maybe Joda-Money might work for you?
 
Robert Van Liew
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Maybe it's more of an intrusive solution than what you were looking for, but maybe Joda-Money might work for you?



A friend forwarded me code that's perfect for what I need, if anyone else stumbles across this thread:

http://stackoverflow.com/questions/10536899/how-to-set-customize-currency-in-java

reply
    Bookmark Topic Watch Topic
  • New Topic