Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

currency

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

like image 694
user288870 Avatar asked Dec 04 '22 13:12

user288870


1 Answers

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"/>
like image 145
Merlin Avatar answered Jan 03 '23 11:01

Merlin