• 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

NumberFormat does not show right currency symbol

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to format a double and display it as a foreign currency. I am using NumberFormat to do this...



Right now this is printing "¤ 1,200.00" in my file, but the symbol for Phillipine Peso is ₱.

Any suggestions? And happy pie day!

Thanks,
Jahan
 
Marshal
Posts: 79278
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using a Windows® command line? That has a restricted repertoire of characters it can display at all. Try it on something like a JOptionPane (showMessageDialog()) and see whether that makes any difference.
By they way, why are you using doubles and not BigDecimal for money?
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running this program within a Tomcat server on Windows. It is writing to a plain text file. Since I am writing to a text file, JOptionPane is not really feasible. Any other suggestions?

And as for the money, I can switch to BigDecimal as you suggested.

Thanks.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jehan Jaleel wrote:I am running this program within a Tomcat server on Windows. It is writing to a plain text file. Since I am writing to a text file, JOptionPane is not really feasible.



Yes it is. You can read from that text file and display in a JOptionPane.

Or you could open that text file with an application and a font that you know can display the character correctly.

You're claiming it's producing the wrong character. Campbell is saying that it may be producing the right character, but that the tool that you're using to view it is interpreting the character incorrectly, or is not capable of displaying the character properly. This could be because the application does not support the encoding or character set, or because the font simply doesn't have a glyph for that character.

Your first step it to determine what character is actually being produced by Java, and viewing that character in a cmd.exe window or in Notepad is not a reliable way to do that.
 
Saloon Keeper
Posts: 15561
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that NumberFormat does not support Filipino. '¤' is a default currency symbol for unknown locales.

For a list of supported Locales, see Locale.getAvailableLocales().

A solution is to print the currency symbol directly.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stephan, I guess that solves it. Although I was kinda hoping that Java would support all currencies.
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jehan Jaleel wrote:I want to format a double and display it as a foreign currency. I am using NumberFormat to do this...



I can't help you with the formatting problem, but *never* use double for currency. It will not work when you try to use arithmetic on it.
Use BigInteger, or make a Currency class and store the values as an integer number of pennies, pence, etc.

Double just doesn't work for money.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic