• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

JSTL fmt:formatNumber does not display currency

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.

 
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Get me the mayor's office! I need to tell her about this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic