wood burning stoves 2.0*
The moose likes JSP and the fly likes JSTL fmt:formatNumber does not display currency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL fmt:formatNumber does not display currency" Watch "JSTL fmt:formatNumber does not display currency" New topic
Author

JSTL fmt:formatNumber does not display currency

lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
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

Joined: Apr 15, 2011
Posts: 1
try by removing the pattern attribute because it might override the currency attributes.
Merlin Weemaes
Greenhorn

Joined: Jan 16, 2012
Posts: 4

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

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

According to the javadoc for java.text.DecimalFormat, it's unicode \u00a4.

Which, according to Wikipedia, is indeed "currency sign".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Merlin Weemaes
Greenhorn

Joined: Jan 16, 2012
Posts: 4

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

Joined: Jan 10, 2002
Posts: 61315
    
  66

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

Joined: Jan 16, 2012
Posts: 4

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.
 
GeeCON Prague 2014
 
subject: JSTL fmt:formatNumber does not display currency