Hi, The jstl tag <fmt:formatNumber> to format currencies, displays the absolute value for negative amounts. For eg: if the amount is -100.00, it gets displayed as (100). Is there anyway to prevent this behaviour? I used the fmt tag as follows : <fmt:formatNumber type="currency" value="${requestScope['selectedLease'].elcoCost.decimalAmount}" currencySymbol=""/> Appreciate any help/suggestions on this.
Thanks Radhika
I did a quick check of what these 2 locales produce:
<c:set var="myvar" value="${-1234567.897}"/>
<fmt:setLocale value="en_US" />
en_US: <fmt:formatNumber type="currency" value="${myvar}" currencySymbol="" />
<fmt:setLocale value="fr_CH" />
fr_CH: <fmt:formatNumber type="currency" value="${myvar}" currencySymbol="" />
produces the following:
en_US: (1,234,567.90) fr_CH: -1'234'567.90
A couple of things you could do:
1. It looks as though you are leaving off the currency symbol, so perhaps you just want a number formatted with 2 decimal places in which case you can try this:
<c:set var="myvar" value="${-1234567.897}"/>
<fmt:setLocale value="en_US" />
en_US: <fmt:formatNumber type="number" value="${myvar}" minFractionDigits="2" maxFractionDigits="2" />
<fmt:setLocale value="fr_CH" />
fr_CH: <fmt:formatNumber type="number" value="${myvar}" minFractionDigits="2" maxFractionDigits="2" />
producing the following: en_US: -1,234,567.90 fr_CH: -1'234'567.90
2. Format using a pattern
You will need to look at java.text.DecimalFormat JavaDocs for help with the pattern but this should work:
<c:set var="myvar" value="${-1234567.897}"/>
<fmt:setLocale value="en_US" />
en_US: <fmt:formatNumber type="number" value="${myvar}" pattern="#,##0.00;-#,##0.00" />
<fmt:setLocale value="fr_CH" />
fr_CH: <fmt:formatNumber type="number" value="${myvar}" pattern="#,##0.00;-#,##0.00" />
producing the following: en_US: -1,234,567.90 fr_CH: -1'234'567.90
The ; in the pattern is the separator for positive and negative patterns.
-- Jason Lea
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
