You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Dominik Bruhn <do...@dbruhn.de> on 2006/05/03 15:06:30 UTC

Double-Calculations in Velocity

Hy,
I wrote this macro:
=====
#macro ( pollbar $total $part $maxwidth $color )
	#set($pc=$part/$total)
	#set ($nw=$pc*$maxwidth)
	<img src="/images/poll/color${color}.gif" width="$nw" height="5" xxx="$pc" />
#end
=====

For some values this works but for the most $nw is 0 afterwards because $pc is 
0. Is this my mistake or is velocity unable to calc in double or float?

Thanks
TO

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Double-Calculations in Velocity

Posted by Tom Schindl <to...@gmx.at>.
What value types are the one in $part and $total if both are integer you
get an integer division as you would in java i suppose.

You can work around this in 2 ways:
- cast one of the operands to double/float
- multiply the ***first*** operand with 1.0

Tom

Dominik Bruhn wrote:
> Hy,
> I wrote this macro:
> =====
> #macro ( pollbar $total $part $maxwidth $color )
> 	#set($pc=$part/$total)
> 	#set ($nw=$pc*$maxwidth)
> 	<img src="/images/poll/color${color}.gif" width="$nw" height="5" xxx="$pc" />
> #end
> =====
> 
> For some values this works but for the most $nw is 0 afterwards because $pc is 
> 0. Is this my mistake or is velocity unable to calc in double or float?
> 
> Thanks
> TO
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 


Re: Double-Calculations in Velocity

Posted by Nathan Bubna <nb...@gmail.com>.
Velocity 1.5-dev does support double or float arithmetic.  prior
releases only support integer math.  for double support in Velocity
1.4, you'll need to use the MathTool from VelocityTools or something
like it.

On 5/3/06, Dominik Bruhn <do...@dbruhn.de> wrote:
> Hy,
> I wrote this macro:
> =====
> #macro ( pollbar $total $part $maxwidth $color )
>         #set($pc=$part/$total)
>         #set ($nw=$pc*$maxwidth)
>         <img src="/images/poll/color${color}.gif" width="$nw" height="5" xxx="$pc" />
> #end
> =====
>
> For some values this works but for the most $nw is 0 afterwards because $pc is
> 0. Is this my mistake or is velocity unable to calc in double or float?
>
> Thanks
> TO
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org