• 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

JSTL fmt:formatNumber does not display currency

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing an issue with fmt:formatNumber jstl tag. I am not able to display the currency symbol. It just contains the amount/ currency value. I tried using currencySymbol ($) as well as currencyCode as USD, but it did not work. Can anyone let me know what is wrong with the code?

The code is:


If the value of price is 2000, c:out displays the amount 2,000 without the currency symbol ($)

Any help is greatly appreciated.

Thanks.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try by removing the pattern attribute because it might override the currency attributes.
 
Greenhorn
Posts: 4
Google Web Toolkit jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use the pattern attribute and you want to display the currency symbol, then you have to add the currency symbol place holder ( ¤ ) to the pattern itself.
The ¤ will be replaced with the given currencySymbol value.

for example:

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. I knew of the possibility of having a currency symbol in a number format string, but I've never actually done it.

My question: what is that symbol placeholder that is being used, and how do I type it on my keyboard???
It looks like an x with a small circle in the middle of it, and is a character I've never really seen before.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the javadoc for java.text.DecimalFormat, it's unicode \u00a4.

Which, according to Wikipedia, is indeed "currency sign".
 
Merlin Weemaes
Greenhorn
Posts: 4
Google Web Toolkit jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Bear said, it is unicode \u00a4, but you can always copy it from this page or the javadoc page ;-). I really don't understand why they chose this character and not just a simple one!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Merlin Weemaes wrote:As Bear said, it is unicode \u00a4, but you can always copy it from this page or the javadoc page ;-).


On a Mac, enable Unicode input in System Prefs, and use the Option key to enter the unicode hex value to create the symbol. I'm sure Windows must have something similar.

Merlin Weemaes wrote:I really don't understand why they chose this character and not just a simple one!


See the links in my reply. It's the symbol that means "some currency". Why shouldn't they use it?
 
Merlin Weemaes
Greenhorn
Posts: 4
Google Web Toolkit jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Merlin Weemaes wrote:I really don't understand why they chose this character and not just a simple one!


See the links in my reply. It's the symbol that means "some currency".


ah, yes, the wikipedia link you just added makes things more clear now :-) At least there is a reason to have chosen this character.

Bear Bibeault wrote:Why shouldn't they use it?


Well, although it is a suitable character, apparently people find it difficult to find/use this character, and that does not make programming easier.
reply
    Bookmark Topic Watch Topic
  • New Topic