commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Radhika Menon" <radsfor...@lycos.com>
Subject Re: fmt:formatNumber to format currency does not display negativeamounts
Date Wed, 20 Aug 2003 21:22:10 GMT
Hi,
Even though I want to suppress the display of the currency symbol, I still want the amount
to be displayed according to the locale, but by retaining the precision supported by the locale
and the "negative" sign.
Is there any way by which we can specify the "pattern" in some place like the message.properties
so that the pattern can be changed based on the user's locale?

Thanks
Radhika


--------- Original Message ---------

DATE: Wed, 20 Aug 2003 09:27:05
From: Jason Lea <jason@kumachan.net.nz>
To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
Cc: 

>Radhika Menon wrote:
>> 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: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>



____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005

Mime
View raw message