user288870
user288870

Reputation: 43

fmt:formatNumber display negative currency in -$xxx.xx format in JSTL

I am using fmt:formatNumber to format currency in JSTL, it will display negative currency in ($100) format, how do I make it display negative currency in negative format instead of ($100)?

thanks very much,

sue

Upvotes: 4

Views: 13113

Answers (3)

JGaudette
JGaudette

Reputation: 106

I would suggest: <fmt:formatNumber type="currency" pattern="$#,##0.00;-$#,##0.00" value="-10000" />

You can remove '$' from the pattern, if you like.

Upvotes: 3

Merlin
Merlin

Reputation: 181

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.

In the example I show two formats in the pattern attribute. One for positive values and one for negative values. They are separated with the semicolon ';'. Both are using the place holder for the currencySymbol.

Example:

<fmt:formatNumber value="-10000" type="currency" currencySymbol="$" pattern="¤ #,##0.00;¤ -#,##0.00"/>

Upvotes: 12

Roopak
Roopak

Reputation: 21

Just to add if u are using type as curreny then currencyCode is required otherwise some random symbol is displayed. If u dont want to use the currencyCode[it will ldisplay what every u have specified in the currecyCode] then use pattern like

<fmt:formatNumber type="currency" pattern="#,##0.00;" value="-10000" />

Upvotes: 2

Related Questions