You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Kienenberger <mk...@alaska.net> on 2005/06/03 23:01:48 UTC
Re: handling -ve currency in $number.format('currency',$myNumber) in
velocity templates
Kailash Sethy <ka...@dot.state.mn.us> wrote:
> Hi Mike,
> If I use the $number.format('currency',$myNumber) for a -ve number,
> the output becomes ($number)
>
> $myNumber -> -13.55
> $number.format('currency',$myNumber) -> ( $13.55)
>
> How to show with -ve sign without parenthesis bracket after
> formatting?
Your best bet is to ask on the velocity-user@jakarta.apache.org mailing
list, to which I've cc'd this message.
Internally, NumberTool just references NumberFormat:
http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html
You can also "cheat" and treat the result of
"$number.getNumberFormat('number', $number.getLocale()))" as a
DecimalFormat, although this may fail for releases other than Velocity 1.3.1
and Velocity Tools 1.1.
#macro (formattedCpac $value $valueIfEmpty)
#set ($cpacFormatter = $number.getNumberFormat('number',
$number.getLocale()))##
${cpacFormatter.setMinimumFractionDigits(5)}##
${cpacFormatter.setMaximumFractionDigits(5)}##
#if($value)${cpacFormatter.format($value)}#else${valueIfEmpty}#end#end
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org