File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL fmt:formatNumber does not display currency

 
lavi mendonca
Ranch Hand
Posts: 53
  • 0
  • 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.
 
bond hello
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try by removing the pattern attribute because it might override the currency attributes.
 
Merlin Weemaes
Greenhorn
Posts: 4
Google Web Toolkit Java jQuery
  • 0
  • 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:

 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • 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.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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 Java jQuery
  • 0
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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 Java jQuery
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic