You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Gustavo De Simone <gu...@swordfish.com.uy> on 2001/03/01 17:32:16 UTC
How do I manipulate real numbers?
Hi ,
As you can see my question is if there any way to manipulate double numbers
in the templates of veocity or if we shoul resolve that before calling to
velocity templates.
I tried something like
$foo=$number1*$number2 where number1 and number2 were double numbers
and aomething like this:
$foo=$number*5.0 and "5.0" wasn't recognized as a number.
thanks,
Gustavo De Simone
Re: How do I manipulate real numbers?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Gustavo De Simone wrote:
>
> Hi ,
> As you can see my question is if there any way to manipulate double numbers
> in the templates of veocity or if we shoul resolve that before calling to
> velocity templates.
>
> I tried something like
>
> $foo=$number1*$number2 where number1 and number2 were double numbers
>
> and aomething like this:
>
> $foo=$number*5.0 and "5.0" wasn't recognized as a number.
Velocity's math support is limited to integer mathematics.
Your best solution would be to either do the math before and place the
values in the context, or if you can't, make a little tool and place
that in the context :
public class MathTool
{
public float mul( float arg1, float arg2 )
{
return arg1 * arg2;
}
etc
}
and use it as
context.put("mathtool", new MathTool() );
in the template
#set($foo = $mathtool.mul( $number 5.0 ) )
(I just typed the above in - no guarantees :)
geir
--
Geir Magnusson Jr. geirm@optonline.com
Developing for the web? See http://jakarta.apache.org/velocity/